Print this page
opendir, dirfd are in XPG7
   1 '\" te
   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 .TH DIRFD 3C "Oct 24, 2007"
   8 .SH NAME
   9 dirfd \- get directory stream file descriptor
  10 .SH SYNOPSIS
  11 .LP
  12 .nf
  13 #include <dirent.h>
  14 
  15 \fBint\fR \fBdirfd\fR(\fBDIR *\fR\fIdir\fR);
  16 .fi
  17 
  18 .SH DESCRIPTION
  19 .sp
  20 .LP
  21 The \fBdirfd()\fR function returns the file descriptor associated with the
  22 directory stream \fIdir\fR.
  23 .sp
  24 .LP
  25 This file descriptor is the one used internally by the directory stream
  26 operations. See \fBopendir\fR(3C), \fBclosedir\fR(3C), \fBreaddir\fR(3C),
  27 \fBrewinddir\fR(3C), \fBseekdir\fR(3C), \fBtelldir\fR(3C).  The file descriptor
  28 is automatically closed when \fBclosedir()\fR is called for the directory
  29 stream \fIdir\fR or when one of the \fBexec\fR functions is called.  See
  30 \fBexec\fR(2).
  31 .sp
  32 .LP










  33 The file descriptor can safely be used only by functions that do not depend on
  34 or alter the file position, such as \fBfstat\fR(2) and \fBfchdir\fR(2).
  35 Closing the file descriptor with \fBclose\fR(2) or modifying the file position





  36 by means other than the directory stream operations listed above causes
  37 undefined behavior to occur when one of the directory stream operations is
  38 subsequently called with the directory stream \fIdir\fR.
  39 .SH RETURN VALUES
  40 .sp
  41 .LP
  42 Upon successful completion, the \fBdirfd()\fR function returns an open file
  43 descriptor for the directory associated with the directory stream \fIdir\fR.
  44 .SH ERRORS
  45 .sp
  46 .LP
  47 There are no defined error returns.  Passing an invalid directory stream as an
  48 argument to the \fBdirfd()\fR function results in undefined behavior.
  49 .SH USAGE
  50 .sp
  51 .LP
  52 The \fBdirfd()\fR function is intended to be used to obtain a file descriptor
  53 for use with the \fBfchdir()\fR function.
  54 .SH ATTRIBUTES
  55 .sp
  56 .LP
  57 See \fBattributes\fR(5) for descriptions of the following attributes:
  58 .sp
  59 
  60 .sp
  61 .TS
  62 box;
  63 c | c
  64 l | l .
  65 ATTRIBUTE TYPE  ATTRIBUTE VALUE
  66 _
  67 Interface Stability     Committed
  68 _
  69 MT-Level        Safe
  70 .TE
  71 
  72 .SH SEE ALSO
  73 .sp
  74 .LP
  75 \fBclose\fR(2), \fBexec\fR(2), \fBfchdir\fR(2), \fBfstat\fR(2),
  76 \fBclosedir\fR(3C), \fBopendir\fR(3C), \fBreaddir\fR(3C), \fBrewinddir\fR(3C),
  77 \fBseekdir\fR(3C), \fBtelldir\fR(3C), \fBattributes\fR(5)





   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 .