Loading...
--- Libc/Libc-1725.40.4/gen/directory.3
+++ Libc/Libc-320/gen/directory.3
@@ -9,7 +9,11 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
@@ -26,14 +30,13 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)directory.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd May 22, 2017
+.\" $FreeBSD: src/lib/libc/gen/directory.3,v 1.12 2001/10/01 16:08:50 ru Exp $
+.\"
+.Dd June 4, 1993
.Dt DIRECTORY 3
.Os
.Sh NAME
.Nm opendir ,
-.Nm fdopendir ,
.Nm readdir ,
.Nm readdir_r ,
.Nm telldir ,
@@ -45,11 +48,10 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
+.In sys/types.h
.In dirent.h
.Ft DIR *
.Fn opendir "const char *filename"
-.Ft DIR *
-.Fn fdopendir "int fd"
.Ft struct dirent *
.Fn readdir "DIR *dirp"
.Ft int
@@ -57,7 +59,7 @@
.Ft long
.Fn telldir "DIR *dirp"
.Ft void
-.Fn seekdir "DIR *dirp" "long loc"
+.Fn seekdir "DIR *dirp" "long loc"
.Ft void
.Fn rewinddir "DIR *dirp"
.Ft int
@@ -65,15 +67,6 @@
.Ft int
.Fn dirfd "DIR *dirp"
.Sh DESCRIPTION
-.Bf -symbolic
-The
-.Fn readdir_r
-interface is deprecated
-because it cannot be used correctly unless
-.Brq Va NAME_MAX
-is a fixed value.
-.Ef
-.Pp
The
.Fn opendir
function
@@ -85,8 +78,7 @@
and
returns a pointer to be used to identify the
.Em directory stream
-in subsequent operations.
-The pointer
+in subsequent operations. The pointer
.Dv NULL
is returned if
.Fa filename
@@ -95,77 +87,20 @@
enough memory to hold the whole thing.
.Pp
The
-.Fn fdopendir
-function is equivalent to the
-.Fn opendir
-function except that the directory is specified by a file descriptor
-.Fa fd
-rather than by a name.
-.\"The file offset associated with the file descriptor at the time of the call
-.\"determines which entries are returned.
-.Pp
-Upon successful return from
-.Fn fdopendir ,
-the file descriptor is under the control of the system,
-and if any attempt is made to close the file descriptor,
-or to modify the state of the associated description other than by means
-of
-.Fn closedir ,
-.Fn readdir ,
-.Fn readdir_r ,
-or
-.Fn rewinddir ,
-the behavior is undefined.
-Upon calling
-.Fn closedir
-the file descriptor is closed.
-The
-.Dv FD_CLOEXEC
-flag is set on the file descriptor by a successful call to
-.Fn fdopendir .
-.Pp
-The
.Fn readdir
function
-returns a pointer to the next directory entry.
-The directory entry remains valid until the next call to
-.Fn readdir
-or
-.Fn closedir
-on the same
-.Em directory stream .
-The function returns
+returns a pointer to the next directory entry. It returns
.Dv NULL
-upon reaching the end of the directory or on error.
-In the event of an error,
-.Va errno
-may be set to any of the values documented for the
-.Xr getdirentries 2
-system call. Note that the order of the directory entries vended by
-.Fn readdir
-is not specified.
-Some filesystems may return entries in lexicographic sort order and others may not.
-Also note that not all filesystems will provide a value for
-.Va d_type
-and may instead set the field to
-.Dv DT_UNKNOWN .
-.Pp
-The
+upon reaching the end of the directory or detecting an invalid
+.Fn seekdir
+operation.
+.Pp
.Fn readdir_r
-function
provides the same functionality as
.Fn readdir ,
but the caller must provide a directory
.Fa entry
-buffer to store the results in.
-The buffer must be large enough for a
-.Vt struct dirent
-with a
-.Va d_name
-array with
-.Brq Va NAME_MAX
-+ 1 elements.
-If the read succeeds,
+buffer to store the results in. If the read succeeds,
.Fa result
is pointed at the
.Fa entry ;
@@ -173,15 +108,13 @@
.Fa result
is set to
.Dv NULL .
-The
.Fn readdir_r
-function
returns 0 on success or an error number to indicate failure.
.Pp
The
.Fn telldir
function
-returns a token representing the current location associated with the named
+returns the current location associated with the named
.Em directory stream .
Values returned by
.Fn telldir
@@ -189,15 +122,10 @@
.Dv DIR
pointer,
.Fa dirp ,
-from which they are derived.
-If the directory is closed and then
+from which they are derived. If the directory is closed and then
reopened, prior values returned by
.Fn telldir
will no longer be valid.
-Values returned by
-.Fn telldir
-are also invalidated by a call to
-.Fn rewinddir .
.Pp
The
.Fn seekdir
@@ -242,18 +170,15 @@
.Pp
Sample code which searches a directory for entry ``name'' is:
.Bd -literal -offset indent
+len = strlen(name);
dirp = opendir(".");
-if (dirp == NULL)
- return (ERROR);
-len = strlen(name);
-while ((dp = readdir(dirp)) != NULL) {
- if (dp->d_namlen == len && strcmp(dp->d_name, name) == 0) {
+while ((dp = readdir(dirp)) != NULL)
+ if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
(void)closedir(dirp);
- return (FOUND);
+ return FOUND;
}
-}
(void)closedir(dirp);
-return (NOT_FOUND);
+return NOT_FOUND;
.Ed
.Sh SEE ALSO
.Xr close 2 ,
@@ -273,7 +198,3 @@
.Fn dirfd
functions appeared in
.Bx 4.2 .
-The
-.Fn fdopendir
-function appeared in
-.Fx 8.0 .