1 .\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
   2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
   3 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
   4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   5 .\" http://www.opengroup.org/bookstore/.
   6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   7 .\"  This notice shall appear on any product containing this material.
   8 .\" 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.
   9 .\" 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.
  10 .\" 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]
  11 .Dd "Jul 22, 2014"
  12 .Dt OPENDIR 3C
  13 .Os
  14 .Sh NAME
  15 .Nm opendir ,
  16 .Nm fdopendir
  17 .Nd open directory
  18 .Sh SYNOPSIS
  19 .In dirent.h
  20 .
  21 .Ft "DIR *"
  22 .Fn opendir "const char *dirname"
  23 .
  24 .Ft "DIR *"
  25 .Fn fdopendir "int fildes"
  26 .
  27 .Sh DESCRIPTION
  28 The
  29 .Fn opendir
  30 function opens a directory stream corresponding to the
  31 directory named by the
  32 .Fa dirname
  33 argument.
  34 .Lp
  35 The
  36 .Fn fdopendir
  37 function opens a directory stream for the directory file
  38 descriptor
  39 .Fa fildes .
  40 The directory file descriptor should not be used or
  41 closed following a successful function call, as this might cause undefined
  42 results from future operations on the directory stream obtained from the call.
  43 Use
  44 .Xr closedir 3C
  45 to close a directory stream.
  46 .Lp
  47 The directory stream is positioned at the first entry. If the type
  48 .Ft DIR
  49 is
  50 implemented using a file descriptor, applications will only be able to open up
  51 to a total of
  52 .Bq OPEN_MAX
  53 files and directories. A successful call to any
  54 of the
  55 .Xr exec 2
  56 functions will close any directory streams that are open in
  57 the calling process.
  58 .Sh RETURN VALUES
  59 Upon successful completion,
  60 .Fn opendir
  61 and
  62 .Fn fdopendir
  63 return a
  64 pointer to an object of type
  65 .Ft DIR .
  66 Otherwise, a null pointer is returned
  67 and
  68 .Va errno
  69 is set to indicate the error.
  70 .Sh ERRORS
  71 The
  72 .Fn opendir
  73 function will fail if:
  74 .Bl -tag -width Er
  75 .It Er EACCES
  76 Search permission is denied for the component of the path prefix of
  77 .Fa dirname
  78 or read permission is denied for
  79 .Fa dirname .
  80 .It Er ELOOP
  81 Too many symbolic links were encountered in resolving
  82 .Fa path .
  83 .It Er ENAMETOOLONG
  84 The length of the
  85 .Fa dirname
  86 argument exceeds
  87 .Brq PATH_MAX ,
  88 or a path name component is longer than
  89 .Brq NAME_MAX
  90 while
  91 .Brq _POSIX_NO_TRUNC
  92 is
  93 in effect.
  94 .It Er ENOENT
  95 A component of
  96 .Fa dirname
  97 does not name an existing directory or
  98 .Fa dirname
  99 is an empty string.
 100 .It Er ENOTDIR
 101 A component of
 102 .Fa dirname
 103 is not a directory.
 104 .El
 105 .Lp
 106 The
 107 .Fn fdopendir
 108 function will fail if:
 109 .Bl -tag -width Er
 110 .It Er ENOTDIR
 111 The file descriptor
 112 .Fa fildes
 113 does not reference a directory.
 114 .El
 115 .Lp
 116 The
 117 .Fn opendir
 118 function may fail if:
 119 .Bl -tag -width Er
 120 .It Er EMFILE
 121 There are
 122 .Brq OPEN_MAX
 123 file descriptors currently open in the calling process.
 124 .It Er ENAMETOOLONG
 125 Pathname resolution of a symbolic link produced an intermediate result whose
 126 length exceeds
 127 .Brq PATH_MAX .
 128 .It Er ENFILE
 129 Too many files are currently open on the system.
 130 .El
 131 .Sh USAGE
 132 The
 133 .Fn opendir
 134 and
 135 .Fn fdopendir
 136 functions should be used in conjunction with
 137 .Xr readdir 3C ,
 138 .Xr closedir 3C
 139 and
 140 .Xr rewinddir 3C
 141 to examine the contents of the directory
 142 .Po see the
 143 .Sx EXAMPLES
 144 section in
 145 .Xr readdir 3C Pc .
 146 This method is recommended for portability.
 147 .Sh INTERFACE STABILITY
 148 .Sy Standard .
 149 .Sh MT-LEVEL
 150 .Sy Safe .
 151 .Sh SEE ALSO
 152 .Xr exec 2 ,
 153 .Xr lstat 2 ,
 154 .Xr symlink 2 ,
 155 .Xr closedir 3C ,
 156 .Xr readdir 3C ,
 157 .Xr rewinddir 3C ,
 158 .Xr scandir 3C ,
 159 .Xr standards 5
 160 .Sh STANDARDS
 161 The
 162 .Fn opendir
 163 function was introduced in
 164 .Bx 4.2 .
 165 and standardized in
 166 .St -p1003.1 .
 167 The
 168 .Fn fdopendir
 169 function was introduced in
 170 .St -p1003.1-2008 .