1 .\" Copyrigh 2014 Garrett D'Amore <garrett@damore.org>
   2 .\" Copyright (c) 2007, Sun Microsystems Inc. All Rights Reserved.
   3 .\" Portions of this manual page are derived from documentation obtained from linuxmanpages.com
   4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
   7 .Dd "Jul 22, 2014"
   8 .Dt DIRFD 3C
   9 .Os
  10 .Sh NAME
  11 .Nm dirfd
  12 .Nd get directory stream file descriptor
  13 .Sh SYNOPSIS
  14 .In dirent.h
  15 .Ft int
  16 .Fn dirfd "DIR *dir"
  17 .Sh DESCRIPTION
  18 The
  19 .Fn dirfd
  20 function returns the file descriptor associated with the
  21 directory stream
  22 .Fa dir .
  23 .Lp
  24 This file descriptor is the one used internally by the directory stream
  25 operations. See
  26 .Xr opendir 3C ,
  27 .Xr closedir 3C ,
  28 .Xr readdir 3C ,
  29 .Xr rewinddir 3C ,
  30 .Xr seekdir 3C ,
  31 and
  32 .Xr telldir 3C .
  33 The file descriptor
  34 is automatically closed when
  35 .Xr closedir 3C
  36 is called for the directory stream
  37 .Fa dir
  38 or when one of the
  39 .Xr exec 2
  40 functions is called.
  41 .Lp
  42 The file descriptor can safely be used only by functions that do not depend on
  43 or alter the file position, such as
  44 .Xr fstat 2
  45 and
  46 .Xr fchdir .
  47 Closing the file descriptor with
  48 .Xr close 2
  49 or modifying the file position
  50 by means other than the directory stream operations listed above causes
  51 undefined behavior to occur when one of the directory stream operations is
  52 subsequently called with the directory stream
  53 .Fa dir .
  54 .Sh RETURN VALUES
  55 Upon successful completion, the
  56 .Fn dirfd
  57 function returns an open file
  58 descriptor for the directory associated with the directory stream
  59 .Fa dir .
  60 .Sh ERRORS
  61 There are no defined error returns.  Passing an invalid directory stream as an
  62 argument to the
  63 .Fn dirfd
  64 function results in undefined behavior.
  65 .Sh USAGE
  66 The
  67 .Fn dirfd
  68 function is intended to be used to obtain a file descriptor
  69 for use with the
  70 .Xr fchdir
  71 function.
  72 .
  73 .Sh INTERFACE STABILITY
  74 .Sy Standard .
  75 .
  76 .Sh MT-LEVEL
  77 .Sy Safe .
  78 .
  79 .Sh SEE ALSO
  80 .Xr close 2 ,
  81 .Xr exec 2 ,
  82 .Xr fchdir 2 ,
  83 .Xr fstat 2 ,
  84 .Xr closedir 3C ,
  85 .Xr opendir 3C ,
  86 .Xr readdir 3C ,
  87 .Xr rewinddir 3C ,
  88 .Xr seekdir 3C ,
  89 .Xr telldir 3C ,
  90 .Xr standards 5
  91 .
  92 .Sh STANDARDS
  93 The
  94 .Fn dirfd
  95 function was introduced in
  96 .St -p1003.1-2008 .