Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162319676
D55024.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D55024.diff
View Options
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
--- a/lib/libc/gen/closedir.c
+++ b/lib/libc/gen/closedir.c
@@ -68,6 +68,5 @@
int
closedir(DIR *dirp)
{
-
return (_close(fdclosedir(dirp)));
}
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 1, 2020
+.Dd January 31, 2026
.Dt DIRECTORY 3
.Os
.Sh NAME
@@ -86,13 +86,6 @@
returns a pointer to be used to identify the
.Em directory stream
in subsequent operations.
-The pointer
-.Dv NULL
-is returned if
-.Fa filename
-cannot be accessed, or if it cannot
-.Xr malloc 3
-enough memory to hold the whole thing.
.Pp
The
.Fn fdopendir
@@ -134,14 +127,6 @@
.Fn closedir
on the same
.Em directory stream .
-The function 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.
.Pp
The
.Fn readdir_r
@@ -166,10 +151,6 @@
.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
@@ -179,12 +160,9 @@
Values returned by
.Fn telldir
are good only for the lifetime of the
-.Dv DIR
-pointer,
-.Fa dirp ,
+.Em directory stream
from which they are derived.
-If the directory is closed and then
-reopened, prior values returned by
+If the directory is closed and then reopened, prior values returned by
.Fn telldir
will no longer be valid.
Values returned by
@@ -217,28 +195,22 @@
function
closes the named
.Em directory stream
-and frees the structure associated with the
-.Fa dirp
-pointer,
-returning 0 on success.
-On failure, \-1 is returned and the global variable
-.Va errno
-is set to indicate the error.
+and frees the structure associated with
+.Fa dirp .
.Pp
The
.Fn fdclosedir
function is equivalent to the
.Fn closedir
-function except that this function returns directory file descriptor instead of
-closing it.
+function except that it returns the file descriptor associated with
+.Fa dirp
+instead of closing it.
.Pp
The
.Fn dirfd
function
-returns the integer file descriptor associated with the named
-.Em directory stream ,
-see
-.Xr open 2 .
+returns the file descriptor associated with
+.Fa dirp .
.Sh EXAMPLES
Sample code which searches a directory for entry ``name'' is:
.Bd -literal -offset indent
@@ -255,6 +227,36 @@
(void)closedir(dirp);
return (NOT_FOUND);
.Ed
+.Sh RETURN VALUES
+The
+.Fn opendir
+and
+.Fn fdopendir
+functions return a pointer to the new
+.Em directory stream
+on success and
+.Dv NULL
+on failure.
+.Pp
+The
+.Fn readdir
+function returns a pointer to a directory entry on success and
+.Dv NULL
+on failure.
+The
+.Fn readdir_r
+function returns 0 on success and an error number on failure.
+.Pp
+The
+.Fn telldir
+function returns a nonnegative value on success and -1 on failure.
+.Pp
+The
+.Fn closedir
+function returns 0 on success and -1 on failure.
+The
+.Fn fdclosedir
+function returns an open file descriptor on success and -1 on failure.
.Sh ERRORS
The
.Fn opendir
diff --git a/lib/libc/gen/dirfd.c b/lib/libc/gen/dirfd.c
--- a/lib/libc/gen/dirfd.c
+++ b/lib/libc/gen/dirfd.c
@@ -27,8 +27,6 @@
*/
#include "namespace.h"
-#include <sys/param.h>
-
#include <dirent.h>
#include "un-namespace.h"
@@ -37,6 +35,5 @@
int
dirfd(DIR *dirp)
{
-
return (_dirfd(dirp));
}
diff --git a/lib/libc/gen/fdopendir.c b/lib/libc/gen/fdopendir.c
--- a/lib/libc/gen/fdopendir.c
+++ b/lib/libc/gen/fdopendir.c
@@ -37,6 +37,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
+#include <stddef.h>
#include "un-namespace.h"
#include "gen-private.h"
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -42,6 +42,5 @@
DIR *
opendir(const char *name)
{
-
return (__opendir2(name, DTF_HIDEW | DTF_NODUP));
}
diff --git a/lib/libc/gen/opendir2.c b/lib/libc/gen/opendir2.c
--- a/lib/libc/gen/opendir2.c
+++ b/lib/libc/gen/opendir2.c
@@ -68,7 +68,6 @@
static int
opendir_compar(const void *p1, const void *p2)
{
-
return (strcmp((*(const struct dirent * const *)p1)->d_name,
(*(const struct dirent * const *)p2)->d_name));
}
diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c
--- a/lib/libc/gen/rewinddir.c
+++ b/lib/libc/gen/rewinddir.c
@@ -43,7 +43,6 @@
void
rewinddir(DIR *dirp)
{
-
if (__isthreaded)
_pthread_mutex_lock(&dirp->dd_lock);
dirp->dd_flags &= ~__DTF_SKIPREAD; /* current contents are invalid */
diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c
--- a/lib/libc/gen/scandir.c
+++ b/lib/libc/gen/scandir.c
@@ -232,14 +232,12 @@
int
alphasort(const struct dirent **d1, const struct dirent **d2)
{
-
return (strcoll((*d1)->d_name, (*d2)->d_name));
}
int
versionsort(const struct dirent **d1, const struct dirent **d2)
{
-
return (strverscmp((*d1)->d_name, (*d2)->d_name));
}
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -53,7 +53,7 @@
if (__isthreaded)
_pthread_mutex_lock(&dirp->dd_lock);
- /*
+ /*
* Outline:
* 1) If the directory position fits in a packed structure, return that.
* 2) Otherwise, see if it's already been recorded in the linked list
@@ -95,7 +95,7 @@
LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe);
}
ddloc.i.is_packed = 0;
- /*
+ /*
* Technically this assignment could overflow on 32-bit architectures,
* but we would get ENOMEM long before that happens.
*/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jul 13, 12:45 AM (12 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35018619
Default Alt Text
D55024.diff (5 KB)
Attached To
Mode
D55024: libc: Clean up *dir() code
Attached
Detach File
Event Timeline
Log In to Comment