diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-10-08 13:52:14 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-10-11 08:29:17 +0200 |
commit | 103b055035fea328f8bc7826801760fb1c055683 (patch) | |
tree | d0a75a2a8c3cdbaf2cd46e0d70628ec5ccc9812a | |
parent | ab4fdab5d555504a90191959546142f797913d84 (diff) | |
download | newlib-103b055035fea328f8bc7826801760fb1c055683.zip newlib-103b055035fea328f8bc7826801760fb1c055683.tar.gz newlib-103b055035fea328f8bc7826801760fb1c055683.tar.bz2 |
Add generic implementation of fdopendir()
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
-rw-r--r-- | newlib/libc/posix/opendir.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/newlib/libc/posix/opendir.c b/newlib/libc/posix/opendir.c index 650cbfe..2cf1ba5 100644 --- a/newlib/libc/posix/opendir.c +++ b/newlib/libc/posix/opendir.c @@ -43,17 +43,11 @@ static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91"; #include <unistd.h> #include <sys/lock.h> -/* - * open a directory. - */ -DIR * -opendir (const char *name) +static DIR * +_opendir_common(int fd) { DIR *dirp; - int fd; - if ((fd = open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1) - return NULL; if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) { close (fd); return NULL; @@ -87,4 +81,23 @@ opendir (const char *name) return dirp; } +DIR * +opendir(const char *name) +{ + int fd; + + if ((fd = open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1) + return (NULL); + return (_opendir_common(fd)); +} + +DIR * +fdopendir(int fd) +{ + + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + return (NULL); + return (_opendir_common(fd)); +} + #endif /* ! HAVE_OPENDIR */ |