diff options
author | Robert de Bath <rdebath@poboxes.com> | 1997-10-05 15:05:09 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:40:02 +0200 |
commit | 48798bf2eb93ec3b99720ac2e16093441156653d (patch) | |
tree | 35e03d95df5f2677f05e32d70abb6d0583aa47ba /libc/gnu_i386/dirent.c | |
parent | 9d97bc3cb3aecd3416fb7c4be3ca2f436665b696 (diff) | |
download | dev86-48798bf2eb93ec3b99720ac2e16093441156653d.tar.gz |
Import Dev86src-0.13.0.tar.gzv0.13.0
Diffstat (limited to 'libc/gnu_i386/dirent.c')
-rw-r--r-- | libc/gnu_i386/dirent.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/libc/gnu_i386/dirent.c b/libc/gnu_i386/dirent.c new file mode 100644 index 0000000..8f7574c --- /dev/null +++ b/libc/gnu_i386/dirent.c @@ -0,0 +1,106 @@ + +#include <errno.h> +#include <sys/types.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <dirent.h> +#include <malloc.h> + +#ifdef L_opendir +DIR * +opendir(dname) +const char *dname; +{ + struct stat st; + int fd; + DIR *p; + + if (stat(dname, &st) < 0) + return 0; + + if (!S_ISDIR(st.st_mode)) + { + errno = ENOTDIR; + return 0; + } + if ((fd = open(dname, O_RDONLY)) < 0) + return 0; + + p = malloc(sizeof(DIR)); + if (p == 0) + { + close(fd); + return 0; + } + + p->dd_buf = malloc(sizeof(struct dirent)); + if (p->dd_buf == 0) + { + free(p); + close(fd); + return 0; + } + p->dd_fd = fd; + p->dd_loc = p->dd_size = 0; + + return p; +} +#endif + +#ifdef L_closedir +int +closedir(dirp) +DIR *dirp; +{ + int fd; + fd = dirp->dd_fd; + free(dirp->dd_buf); + free(dirp); + return close(fd); +} +#endif + +#ifdef __AS386_16__ +#ifdef L_readdir +/* + * This currently assumes we see a v. simple diectory structure, it's + * probably faked! + */ +struct dirent * +readdir(dirp) +DIR *dirp; +{ + int cc; + cc = read(dirp->dd_fd, dirp->dd_buf, sizeof(struct dirent)); + + if (cc <= 0) + return 0; + if (cc != sizeof(struct dirent)) + { + errno = EBADF; + return 0; + } + return dirp->dd_buf; +} +#endif +#else + +/* This is for 386 linux */ + +#ifdef L_readdir +struct dirent * +readdir(dirp) +DIR *dirp; +{ + int cc; + + cc = __readdir(dirp->dd_fd, dirp->dd_buf, 1); + if (cc <= 0) + return 0; + if (cc>1) dirp->dd_buf->d_name[cc] = 0; + + return dirp->dd_buf; +} +#endif + +#endif |