Add generic implementation of fdopendir()
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
This commit is contained in:
parent
ab4fdab5d5
commit
103b055035
|
@ -43,17 +43,11 @@ static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91";
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/lock.h>
|
#include <sys/lock.h>
|
||||||
|
|
||||||
/*
|
static DIR *
|
||||||
* open a directory.
|
_opendir_common(int fd)
|
||||||
*/
|
|
||||||
DIR *
|
|
||||||
opendir (const char *name)
|
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
int fd;
|
|
||||||
|
|
||||||
if ((fd = open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1)
|
|
||||||
return NULL;
|
|
||||||
if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
|
if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
|
||||||
close (fd);
|
close (fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -87,4 +81,23 @@ opendir (const char *name)
|
||||||
return dirp;
|
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 */
|
#endif /* ! HAVE_OPENDIR */
|
||||||
|
|
Loading…
Reference in New Issue