summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/opendir.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2008-04-16 18:59:36 +0000
committerdelphij <delphij@FreeBSD.org>2008-04-16 18:59:36 +0000
commit6de397fa88cf56d8b432e839cf7738e7f48da0fc (patch)
tree8c9b74f319a953968d992cfa91a87e7fe29827a0 /lib/libc/gen/opendir.c
parent71f117505a34b4de451c2ace38b596babde8aca4 (diff)
downloadFreeBSD-src-6de397fa88cf56d8b432e839cf7738e7f48da0fc.zip
FreeBSD-src-6de397fa88cf56d8b432e839cf7738e7f48da0fc.tar.gz
Implement fdopendir(3) by splitting __opendir2() into two parts, the upper part
deals with the usual __opendir2() calls, and the rest part with an interface translator to expose fdopendir(3) functionality. Manual page was obtained from kib@'s work for *at(2) system calls.
Diffstat (limited to 'lib/libc/gen/opendir.c')
-rw-r--r--lib/libc/gen/opendir.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 5725ca3..9625ec6 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -47,6 +47,9 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "telldir.h"
+
+static DIR * __opendir_common(int, const char *, int);
+
/*
* Open a directory.
*/
@@ -57,19 +60,25 @@ opendir(const char *name)
return (__opendir2(name, DTF_HIDEW|DTF_NODUP));
}
+/*
+ * Open a directory with existing file descriptor.
+ */
+DIR *
+fdopendir(int fd)
+{
+
+ return (__opendir_common(fd, NULL, DTF_HIDEW|DTF_NODUP));
+}
+
DIR *
__opendir2(const char *name, int flags)
{
- DIR *dirp;
int fd;
- int incr;
- int saved_errno;
- int unionstack;
struct stat statb;
/*
* stat() before _open() because opening of special files may be
- * harmful. _fstat() after open because the file may have changed.
+ * harmful.
*/
if (stat(name, &statb) != 0)
return (NULL);
@@ -79,7 +88,24 @@ __opendir2(const char *name, int flags)
}
if ((fd = _open(name, O_RDONLY | O_NONBLOCK)) == -1)
return (NULL);
+
+ return __opendir_common(fd, name, flags);
+}
+
+/*
+ * Common routine for opendir(3), __opendir2(3) and fdopendir(3).
+ */
+static DIR *
+__opendir_common(int fd, const char *name, int flags)
+{
+ DIR *dirp;
+ int incr;
+ int saved_errno;
+ int unionstack;
+ struct stat statb;
+
dirp = NULL;
+ /* _fstat() the open handler because the file may have changed. */
if (_fstat(fd, &statb) != 0)
goto fail;
if (!S_ISDIR(statb.st_mode)) {
OpenPOWER on IntegriCloud