xref: /illumos-gate/usr/src/man/man3c/opendir.3c (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
166492cf0SYuri Pankov.\"
266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation.
466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at
5c10c16deSRichard Lowe.\" http://www.opengroup.org/bookstore/.
666492cf0SYuri Pankov.\"
766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open
866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their
966492cf0SYuri Pankov.\" documentation.
1066492cf0SYuri Pankov.\"
1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions
1266492cf0SYuri Pankov.\" of the system documentation.
1366492cf0SYuri Pankov.\"
1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form
1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System
1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group
2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee
2266492cf0SYuri Pankov.\" document.  The original Standard can be obtained online at
2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html.
2466492cf0SYuri Pankov.\"
25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material.
2666492cf0SYuri Pankov.\"
2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the
2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License").
2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License.
3066492cf0SYuri Pankov.\"
3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing.
3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions
3466492cf0SYuri Pankov.\" and limitations under the License.
3566492cf0SYuri Pankov.\"
3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each
3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the
3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying
4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner]
4166492cf0SYuri Pankov.\"
4266492cf0SYuri Pankov.\"
4366492cf0SYuri Pankov.\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
4466492cf0SYuri Pankov.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
453aa10614SRobert Mustacchi.\" Copyright 2021 Oxide Computer Company
4666492cf0SYuri Pankov.\"
473aa10614SRobert Mustacchi.Dd February 25, 2021
483aa10614SRobert Mustacchi.Dt OPENDIR 3C
493aa10614SRobert Mustacchi.Os
503aa10614SRobert Mustacchi.Sh NAME
513aa10614SRobert Mustacchi.Nm opendir ,
523aa10614SRobert Mustacchi.Nm fdopendir
533aa10614SRobert Mustacchi.Nd open directory stream
543aa10614SRobert Mustacchi.Sh SYNOPSIS
553aa10614SRobert Mustacchi.In sys/types.h
563aa10614SRobert Mustacchi.In dirent.h
573aa10614SRobert Mustacchi.Ft "DIR *"
583aa10614SRobert Mustacchi.Fo opendir
593aa10614SRobert Mustacchi.Fa "dirname"
603aa10614SRobert Mustacchi.Fc
613aa10614SRobert Mustacchi.Ft "DIR *"
623aa10614SRobert Mustacchi.Fo fdopendir
633aa10614SRobert Mustacchi.Fa "int filedes"
643aa10614SRobert Mustacchi.Fc
653aa10614SRobert Mustacchi.Sh DESCRIPTION
663aa10614SRobert MustacchiThe
673aa10614SRobert Mustacchi.Fn opendir
683aa10614SRobert Mustacchiand
693aa10614SRobert Mustacchi.Fn fdopendir
703aa10614SRobert Mustacchifunctions are used to create seekable directory streams that can be used
713aa10614SRobert Mustacchito iterate over the contents of a directory, most commonly with
723aa10614SRobert Mustacchi.Xr readdir 3C .
733aa10614SRobert MustacchiOne can traverse and seek the stream with functions such as
743aa10614SRobert Mustacchi.Xr seekdir 3C ,
753aa10614SRobert Mustacchi.Xr telldir 3C ,
763aa10614SRobert Mustacchiand
773aa10614SRobert Mustacchi.Xr rewinddir 3C .
783aa10614SRobert Mustacchi.Pp
793aa10614SRobert MustacchiThe
803aa10614SRobert Mustacchi.Fn opendir
813aa10614SRobert Mustacchifunction creates a directory stream from the path named by
823aa10614SRobert Mustacchi.Fa dirname .
833aa10614SRobert MustacchiThe
843aa10614SRobert Mustacchi.Fn fdopendir
853aa10614SRobert Mustacchifunction creates a directory stream from an already opened file
863aa10614SRobert Mustacchidescriptor,
873aa10614SRobert Mustacchi.Fa filedes ,
883aa10614SRobert Mustacchithat refers to a directory.
893aa10614SRobert MustacchiAfter successfully calling
903aa10614SRobert Mustacchi.Fn fdopendir ,
913aa10614SRobert Mustacchi.Fa filedes
923aa10614SRobert Mustacchibelongs to the system and the application must not modify or close it in
933aa10614SRobert Mustacchiany way.
943aa10614SRobert Mustacchi.Pp
953aa10614SRobert MustacchiThe new directory stream is positioned at the first entry.
963aa10614SRobert MustacchiWhen finished with the directory stream, the caller is responsible for
973aa10614SRobert Mustacchireleasing its resources by calling the
983aa10614SRobert Mustacchi.Xr closedir 3C
993aa10614SRobert Mustacchifunction.
1003aa10614SRobert MustacchiThis will close the directory stream's underlying file descriptor,
1013aa10614SRobert Mustacchiincluding
1023aa10614SRobert Mustacchi.Fa filedes
1033aa10614SRobert Mustacchiif
1043aa10614SRobert Mustacchi.Fn fdopendir
1053aa10614SRobert Mustacchiwas used to create it.
1063aa10614SRobert MustacchiIn addition, memory associated with the directory stream, such as the
1073aa10614SRobert Mustacchi.Ft struct dirent
1083aa10614SRobert Mustacchireturned from
1093aa10614SRobert Mustacchi.Xr readdir 3C
1103aa10614SRobert Mustacchiwill be invalid once a call to
1113aa10614SRobert Mustacchi.Xr closedir 3C
1123aa10614SRobert Mustacchiis completed.
1133aa10614SRobert Mustacchi.Pp
1143aa10614SRobert MustacchiAll directory streams are closed upon a successful call to any of the
1153aa10614SRobert Mustacchi.Xr exec 2
1163aa10614SRobert Mustacchifamily of functions.
1173aa10614SRobert MustacchiThe underlying file descriptors behave as though the
1183aa10614SRobert Mustacchi.Dv FD_CLOEXEC
1193aa10614SRobert Mustacchiflag was set upon them.
1203aa10614SRobert Mustacchi.Pp
1213aa10614SRobert MustacchiDirectory streams created by the
1223aa10614SRobert Mustacchi.Fn opendir
1233aa10614SRobert Mustacchifunction require an underlying file descriptor.
1243aa10614SRobert MustacchiAs a result, applications are only able to open up to a total of
1253aa10614SRobert Mustacchi.Brq Dv OPEN_MAX
1263aa10614SRobert Mustacchifiles and directories.
1273aa10614SRobert Mustacchi.Sh RETURN VALUES
1283aa10614SRobert MustacchiUpon successful completion, the
1293aa10614SRobert Mustacchi.Fn opendir
1303aa10614SRobert Mustacchiand
1313aa10614SRobert Mustacchi.Fn fdopendir
1323aa10614SRobert Mustacchifunctions return a pointer to an object of type
1333aa10614SRobert MustacchiFt DIR .
1343aa10614SRobert MustacchiOtherwise, a null pointer is returned and
1353aa10614SRobert Mustacchi.Va errno
1363aa10614SRobert Mustacchiis set to indicate the error.
1373aa10614SRobert Mustacchi.Sh ERRORS
1383aa10614SRobert MustacchiThe
1393aa10614SRobert Mustacchi.Fn opendir
1403aa10614SRobert Mustacchifunction will fail if:
1413aa10614SRobert Mustacchi.Bl -tag -width Er
1423aa10614SRobert Mustacchi.It Er EACCES
1433aa10614SRobert MustacchiSearch permission is denied for any component of the path prefix of
1443aa10614SRobert Mustacchi.Fa dirname
1453aa10614SRobert Mustacchior read permission is denied for
1463aa10614SRobert Mustacchi.Fa Idirname .
1473aa10614SRobert Mustacchi.It Er ELOOP
1483aa10614SRobert MustacchiToo many symbolic links were encountered in resolving
1493aa10614SRobert Mustacchi.Fa path .
1503aa10614SRobert Mustacchi.It Er ENAMETOOLONG
1513aa10614SRobert MustacchiThe length of the
1523aa10614SRobert Mustacchi.Fa dirname
1533aa10614SRobert Mustacchiargument exceeds
1543aa10614SRobert Mustacchi.Brq Dv PATH_MAX ,
1553aa10614SRobert Mustacchior a path name component is longer than
1563aa10614SRobert Mustacchi.Brq Dv NAME_MAX
1573aa10614SRobert Mustacchiwhile
1583aa10614SRobert Mustacchi.Brq Dv _POSIX_NO_TRUNC
1593aa10614SRobert Mustacchiis in effect.
1603aa10614SRobert Mustacchi.It Er ENOENT
1613aa10614SRobert MustacchiA component of
1623aa10614SRobert Mustacchi.Fa dirname
1633aa10614SRobert Mustacchidoes not name an existing directory or
1643aa10614SRobert Mustacchi.Fa dirname
1653aa10614SRobert Mustacchiis an empty string.
1663aa10614SRobert Mustacchi.It Er ENOTDIR
1673aa10614SRobert MustacchiA component of
1683aa10614SRobert Mustacchi.Fa dirname
1693aa10614SRobert Mustacchiis not a directory.
1703aa10614SRobert Mustacchi.El
1713aa10614SRobert Mustacchi.Pp
1723aa10614SRobert MustacchiThe
1733aa10614SRobert Mustacchi.Fn fdopendir
1743aa10614SRobert Mustacchifunction will fail if:
1753aa10614SRobert Mustacchi.Bl -tag -width Er
1763aa10614SRobert Mustacchi.It Er ENOTDIR
1773aa10614SRobert MustacchiThe file descriptor
1783aa10614SRobert Mustacchi.Fa filedes
1793aa10614SRobert Mustacchidoes not reference a directory.
1803aa10614SRobert Mustacchi.El
1813aa10614SRobert Mustacchi.Pp
1823aa10614SRobert MustacchiThe
1833aa10614SRobert Mustacchi.Fn opendir
1843aa10614SRobert Mustacchifunction may fail if:
1853aa10614SRobert Mustacchi.Bl -tag -width Er
1863aa10614SRobert Mustacchi.It Er EMFILE
1873aa10614SRobert MustacchiThere are already
1883aa10614SRobert Mustacchi.Brq Dv OPEN_MAX
1893aa10614SRobert Mustacchifile descriptors currently open in the calling process.
1903aa10614SRobert Mustacchi.It Er ENAMETOOLONG
191c10c16deSRichard LowePathname resolution of a symbolic link produced an intermediate result whose
1923aa10614SRobert Mustacchilength exceeds
1933aa10614SRobert Mustacchi.Dv PATH_MAX .
1943aa10614SRobert Mustacchi.It Er ENFILE
195c10c16deSRichard LoweToo many files are currently open on the system.
1963aa10614SRobert Mustacchi.El
1973aa10614SRobert Mustacchi.Sh INTERFACE STABILITY
1983aa10614SRobert Mustacchi.Sy Committed
1993aa10614SRobert Mustacchi.Sh MT-LEVEL
2003aa10614SRobert Mustacchi.Sy Safe
2013aa10614SRobert Mustacchi.Sh SEE ALSO
2023aa10614SRobert Mustacchi.Xr lstat 2 ,
2033aa10614SRobert Mustacchi.Xr symlink 2 ,
2043aa10614SRobert Mustacchi.Xr closedir 3C ,
2053aa10614SRobert Mustacchi.Xr readdir 3C ,
2063aa10614SRobert Mustacchi.Xr rewinddir 3C ,
2073aa10614SRobert Mustacchi.Xr seekdir 3C ,
2083aa10614SRobert Mustacchi.Xr telldir 3C ,
209*bbf21555SRichard Lowe.Xr attributes 7
210