Library/libs: add telldir, seekdir and rewinddir
authorFaisal Abbas <90.abbasfaisal@gmail.com>
Sun, 8 Nov 2015 16:16:00 +0000 (21:16 +0500)
committerAlan Cox <alan@linux.intel.com>
Sun, 8 Nov 2015 16:51:31 +0000 (16:51 +0000)
 - Also set reclen to 31 in readdir.
 - Tested on z80pack.
 - Only compile-tested on 6809.

Library/libs/Makefile
Library/libs/Makefile.6809
Library/libs/opendir.c
Library/libs/readdir.c
Library/libs/rewinddir.c [new file with mode: 0644]
Library/libs/seekdir.c [new file with mode: 0644]
Library/libs/telldir.c [new file with mode: 0644]

index 88a26d1..84602c4 100644 (file)
@@ -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
index aab5d6b..67314d5 100644 (file)
@@ -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
index 30e06ff..fc9126b 100644 (file)
@@ -26,5 +26,7 @@ DIR *opendir(char *path)
                free(dir);
                return NULL;
        }
+
+       dir->d.dd_loc = 0;
        return (DIR *)dir;
 }
index 924e663..9a40308 100644 (file)
@@ -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 (file)
index 0000000..910be84
--- /dev/null
@@ -0,0 +1,9 @@
+#include <dirent.h>
+#include <unistd.h>
+
+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 (file)
index 0000000..25e7813
--- /dev/null
@@ -0,0 +1,9 @@
+#include <dirent.h>
+#include <unistd.h>
+
+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 (file)
index 0000000..5e13e28
--- /dev/null
@@ -0,0 +1,7 @@
+#include <dirent.h>
+
+off_t telldir(DIR * dirp)
+{
+       struct _dir *dir = (struct _dir *)dirp;
+       return dir->d.dd_loc;
+}