Provide a man page for Alfreds lovely readdir_r function. Also
fixed a minor indentation nit and added a few {}s to make readdir_r easier on old eyes.
This commit is contained in:
parent
5fb9b023ec
commit
00ecacd3c4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53872
@ -38,6 +38,7 @@
|
||||
.Sh NAME
|
||||
.Nm opendir ,
|
||||
.Nm readdir ,
|
||||
.Nm readdir_r ,
|
||||
.Nm telldir ,
|
||||
.Nm seekdir ,
|
||||
.Nm rewinddir ,
|
||||
@ -51,6 +52,8 @@
|
||||
.Fn opendir "const char *filename"
|
||||
.Ft struct dirent *
|
||||
.Fn readdir "DIR *dirp"
|
||||
.Ft int
|
||||
.Fn readdir_r "DIR *dirp" "struct dirent *entry" "struct dirent **result"
|
||||
.Ft long
|
||||
.Fn telldir "const DIR *dirp"
|
||||
.Ft void
|
||||
@ -90,6 +93,22 @@ upon reaching the end of the directory or detecting an invalid
|
||||
.Fn seekdir
|
||||
operation.
|
||||
.Pp
|
||||
.Fn readdir_r
|
||||
provides the same functionality as
|
||||
.Fn readdir ,
|
||||
but the caller must provide a directory
|
||||
.Fa entry
|
||||
buffer to store the results in. If the read succeeds,
|
||||
.Fa result
|
||||
is pointed at the
|
||||
.Fa entry ;
|
||||
upon reaching the end of the directory
|
||||
.Fa result
|
||||
is set to
|
||||
.Dv NULL .
|
||||
.Fn readdir_r
|
||||
returns 0 on success or an error number to indicate failure.
|
||||
.Pp
|
||||
The
|
||||
.Fn telldir
|
||||
function
|
||||
|
@ -95,8 +95,9 @@ readdir_r(dirp, entry, result)
|
||||
return EBADF;
|
||||
}
|
||||
#ifdef _THREAD_SAFE
|
||||
if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0)
|
||||
if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
errno = 0;
|
||||
dp = readdir(dirp);
|
||||
@ -106,14 +107,16 @@ readdir_r(dirp, entry, result)
|
||||
#endif
|
||||
return errno;
|
||||
}
|
||||
if (dp != NULL)
|
||||
if (dp != NULL) {
|
||||
memcpy(entry, dp, sizeof *entry);
|
||||
}
|
||||
#ifdef _THREAD_SAFE
|
||||
_FD_UNLOCK(dirp->dd_fd, FD_READ);
|
||||
#endif
|
||||
if (dp != NULL)
|
||||
*result = entry;
|
||||
else
|
||||
if (dp != NULL) {
|
||||
*result = entry;
|
||||
} else {
|
||||
*result = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user