From 5abbb0b968772e4c924deed9ade511d6454f75dd Mon Sep 17 00:00:00 2001 From: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Sun, 8 Nov 2015 21:16:00 +0500 Subject: [PATCH] Library/libs: add telldir, seekdir and rewinddir - Also set reclen to 31 in readdir. - Tested on z80pack. - Only compile-tested on 6809. --- Library/libs/Makefile | 4 ++-- Library/libs/Makefile.6809 | 4 ++-- Library/libs/opendir.c | 2 ++ Library/libs/readdir.c | 4 ++-- Library/libs/rewinddir.c | 9 +++++++++ Library/libs/seekdir.c | 9 +++++++++ Library/libs/telldir.c | 7 +++++++ 7 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 Library/libs/rewinddir.c create mode 100644 Library/libs/seekdir.c create mode 100644 Library/libs/telldir.c diff --git a/Library/libs/Makefile b/Library/libs/Makefile index 88a26d16..84602c4f 100644 --- a/Library/libs/Makefile +++ b/Library/libs/Makefile @@ -37,12 +37,12 @@ SRC_C += localtim.c localtim_r.c lseek.c lsearch.c lstat.c ltoa.c ltostr.c SRC_C += malloc.c mkfifo.c mkstemps.c nanosleep.c opendir.c pause.c perror.c SRC_C += popen.c printf.c putenv.c putgetch.c putpwent.c putw.c pwent.c qsort.c SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c -SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c +SRC_C += regsub.c remove.c rewind.c rewinddir.c rindex.c seekdir.c setbuffer.c setenv.c SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c SRC_C += stat.c stdio0.c stime.c SRC_C += strcasecmp.c strcasestr.c strdup.c stricmp.c strlcpy.c strncasecmp.c SRC_C += strnlen.c strnicmp.c strsep.c strxfrm.c strcoll.c strsignal.c -SRC_C += strtod.c strtol.c swab.c system.c time.c tmpfile.c tmpnam.c ttyname.c +SRC_C += strtod.c strtol.c swab.c system.c telldir.c time.c tmpfile.c tmpnam.c ttyname.c SRC_C += tzset.c ungetc.c usleep.c utent.c utimes.c utsname.c SRC_C += vfprintf.c vprintf.c wait.c xitoa.c pathconf.c SRC_C += gethostname.c sysconf.c confstr.c memccpy.c getpass.c diff --git a/Library/libs/Makefile.6809 b/Library/libs/Makefile.6809 index aab5d6b2..67314d5c 100644 --- a/Library/libs/Makefile.6809 +++ b/Library/libs/Makefile.6809 @@ -29,12 +29,12 @@ SRC_C += localtim.c localtim_r.c lseek.c lsearch.c lstat.c ltoa.c ltostr.c SRC_C += malloc.c mkfifo.c mkstemps.c nanosleep.c opendir.c pause.c perror.c SRC_C += popen.c printf.c putenv.c putchar.c putpwent.c putw.c pwent.c qsort.c SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c -SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c +SRC_C += regsub.c remove.c rewind.c rewinddir.c rindex.c seekdir.c setbuffer.c setenv.c SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c SRC_C += stat.c stdio0.c stime.c SRC_C += strcasecmp.c strcasestr.c strdup.c stricmp.c strlcpy.c strncasecmp.c SRC_C += strnlen.c strnicmp.c strsep.c strsignal.c strxfrm.c strcoll.c -SRC_C += strtod.c strtol.c swab.c system.c time.c tmpfile.c tmpnam.c ttyname.c +SRC_C += strtod.c strtol.c swab.c system.c telldir.c time.c tmpfile.c tmpnam.c ttyname.c SRC_C += tzset.c ungetc.c usleep.c utent.c utimes.c utsname.c SRC_C += vfprintf.c vprintf.c wait.c xitoa.c pathconf.c SRC_C += gethostname.c sysconf.c confstr.c memccpy.c getpass.c diff --git a/Library/libs/opendir.c b/Library/libs/opendir.c index 30e06ff7..fc9126be 100644 --- a/Library/libs/opendir.c +++ b/Library/libs/opendir.c @@ -26,5 +26,7 @@ DIR *opendir(char *path) free(dir); return NULL; } + + dir->d.dd_loc = 0; return (DIR *)dir; } diff --git a/Library/libs/readdir.c b/Library/libs/readdir.c index 924e6633..9a403082 100644 --- a/Library/libs/readdir.c +++ b/Library/libs/readdir.c @@ -27,7 +27,6 @@ struct dirent *readdir(DIR * dirp) struct _dir *dir = (struct _dir *)dirp; struct __dirent *direntry; register struct dirent *buf; - int len; if (dir == NULL || dir->d.dd_fd == -1) { errno = EFAULT; @@ -43,7 +42,8 @@ struct dirent *readdir(DIR * dirp) buf = &dir->de; buf->d_ino = direntry->d_ino; buf->d_off = -1; /* FIXME */ - buf->d_reclen = 33; + buf->d_reclen = 31; + dir->d.dd_loc += (buf->d_reclen + 1); strncpy(buf->d_name, (char *) direntry->d_name, 31); buf->d_name[30] = 0; return buf; diff --git a/Library/libs/rewinddir.c b/Library/libs/rewinddir.c new file mode 100644 index 00000000..910be84b --- /dev/null +++ b/Library/libs/rewinddir.c @@ -0,0 +1,9 @@ +#include +#include + +void rewinddir(DIR *dirp) +{ + struct _dir *dir = (struct _dir *)dirp; + lseek(dir->d.dd_fd, dir->d.dd_loc = 0, SEEK_SET); + dir->next = dir->last = 0; +} diff --git a/Library/libs/seekdir.c b/Library/libs/seekdir.c new file mode 100644 index 00000000..25e7813d --- /dev/null +++ b/Library/libs/seekdir.c @@ -0,0 +1,9 @@ +#include +#include + +void seekdir (DIR * dirp, off_t pos) +{ + struct _dir *dir = (struct _dir *)dirp; + lseek(dir->d.dd_fd, dir->d.dd_loc = pos, SEEK_SET); + dir->next = dir->last = 0; +} diff --git a/Library/libs/telldir.c b/Library/libs/telldir.c new file mode 100644 index 00000000..5e13e28f --- /dev/null +++ b/Library/libs/telldir.c @@ -0,0 +1,7 @@ +#include + +off_t telldir(DIR * dirp) +{ + struct _dir *dir = (struct _dir *)dirp; + return dir->d.dd_loc; +} -- 2.34.1