Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F143980359
D55025.id170986.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D55025.id170986.diff
View Options
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
@@ -256,7 +256,9 @@
function returns 0 on success and -1 on failure.
The
.Fn fdclosedir
-function returns an open file descriptor on success and -1 on failure.
+and
+.Fn dirfd
+functions return an open file descriptor on success and -1 on failure.
.Sh ERRORS
The
.Fn opendir
@@ -327,6 +329,16 @@
.Va errno
for any of the errors specified for the routine
.Xr close 2 .
+.Pp
+The
+.Fn dirfd
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Fa dirp
+argument does not refer to a valid directory stream.
+.El
.Sh SEE ALSO
.Xr close 2 ,
.Xr lseek 2 ,
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
@@ -28,6 +28,7 @@
#include "namespace.h"
#include <dirent.h>
+#include <errno.h>
#include "un-namespace.h"
#include "gen-private.h"
@@ -35,5 +36,9 @@
int
dirfd(DIR *dirp)
{
+ if (dirp == NULL || _dirfd(dirp) < 0) {
+ errno = EINVAL;
+ return (-1);
+ }
return (_dirfd(dirp));
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Feb 3, 9:53 PM (9 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28425954
Default Alt Text
D55025.id170986.diff (1 KB)
Attached To
Mode
D55025: libc: Improve POSIX conformance of dirfd()
Attached
Detach File
Event Timeline
Log In to Comment