Mail Archives: cygwin-developers/1999/03/12/17:32:09
Hi,
attached is a small patch to winsup, which implements the
functions telldir() and seekdir(). They are using the
currently unused struct element DIR::__d_find_first_called
to remember the position for tell and seek.
Of course, the file `dirent.h' from newlib/libc/sys/cygwin/sys is
changed, too.
Regards,
Corinna
ChangeLog:
==========
Fri Mar 12 23:23:00 Corinna Vinschen <corinna DOT vinschen AT cityweb DOT de>
* dir.cc: New functions `telldir()' and `seekdir()'.
* cygwin.def: Ditto.
* newlib/libc/sys/cygwin/sys/dirent.h: Additional prototypes
for `telldir()' and `seekdir()'.
======== snip ========
--- dir.cc 1999/03/07 22:05:34 1.3
+++ dir.cc 1999/03/12 22:11:22
@@ -106,2 +106,3 @@ opendir (const char *dirname)
dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
+ dir->__d_find_first_called = 0;
dir->__d_dirhash = statbuf.st_ino;
@@ -202,2 +203,3 @@ readdir (DIR * dir)
+ ++dir->__d_find_first_called;
res = dir->__d_dirent;
@@ -206,2 +208,22 @@ readdir (DIR * dir)
return res;
+}
+
+/* telldir */
+extern "C"
+off_t
+telldir (DIR * dir)
+{
+ return (off_t) dir->__d_find_first_called;
+}
+
+/* seekdir */
+extern "C"
+void
+seekdir (DIR * dir, off_t loc)
+{
+ rewinddir (dir);
+ dir->__d_find_first_called = 0;
+ while (loc > dir->__d_find_first_called)
+ if (! readdir (dir))
+ break;
}
--- cygwin.def.orig Sat Mar 13 00:25:27 1999
+++ cygwin.def Sat Mar 13 00:12:58 1999
@@ -495,2 +495,4 @@ random
initstate
+seekdir
+_seekdir = seekdir
setstate
@@ -727,2 +729,4 @@ tcsetpgrp
_tcsetpgrp = tcsetpgrp
+telldir
+_telldir = telldir
tempnam
--- newlib/libc/sys/cygwin/sys/dirent.h.orig Sat Mar 13 00:27:01 1999
+++ newlib/libc/sys/cygwin/sys/dirent.h Sat Mar 13 00:06:46 1999
@@ -41,2 +41,4 @@ typedef struct
DIR *opendir (const char *);
+off_t telldir (DIR *);
+void seekdir (DIR *, off_t loc);
struct dirent *readdir (DIR *);
- Raw text -