Page MenuHomeFreeBSD

D55025.id170986.diff
No OneTemporary

D55025.id170986.diff

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

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)

Event Timeline