From 02fec4701cee79f875c1d02b8b4aee09380dbcb8 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Thu, 4 Jan 2001 20:04:45 +0000 Subject: integrate dietlibc/stdio per default for cdrom and disk only installs --- mdk-stage1/dietlibc/lib/opendir.c | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 mdk-stage1/dietlibc/lib/opendir.c (limited to 'mdk-stage1/dietlibc/lib/opendir.c') diff --git a/mdk-stage1/dietlibc/lib/opendir.c b/mdk-stage1/dietlibc/lib/opendir.c new file mode 100644 index 000000000..05c0b9bc8 --- /dev/null +++ b/mdk-stage1/dietlibc/lib/opendir.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#undef _POSIX_PTHREADS +#include + +#include "dirstream.h" + +#ifndef O_DIRECTORY +#define O_DIRECTORY 0200000 /* must be a directory */ +#endif + +/* + * opendir just makes an open() call - it return NULL if it fails + * (open sets errno), otherwise it returns a DIR * pointer. + */ +#undef opendir +DIR * +opendir(const char * name) +{ + int fd; + struct stat statbuf; + struct dirent *buf; + DIR *ptr; + + /* + if (stat(name,&statbuf)) return NULL; + if (!S_ISDIR(statbuf.st_mode)) { + errno = ENOTDIR; + return NULL; + } + */ + if ((fd = open(name,O_RDONLY|O_DIRECTORY)) < 0) + return NULL; + /* According to POSIX, directory streams should be closed when + * exec. From "Anna Pluzhnikov" . + */ + if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) + return NULL; + if (!(ptr=malloc(sizeof(*ptr)))) { + close(fd); + errno = ENOMEM; + return NULL; + } + + ptr->dd_max = statbuf.st_blksize; + if (ptr->dd_max < 512) + ptr->dd_max = 512; + + if (!(buf=malloc(ptr->dd_max))) { + close(fd); + free(ptr); + errno = ENOMEM; + return NULL; + } + ptr->dd_fd = fd; + ptr->dd_nextoff = ptr->dd_nextloc = ptr->dd_size = 0; + ptr->dd_buf = buf; + ptr->dd_getdents = unknown; + return ptr; +} -- cgit v1.2.1