Index: gen/gen-private.h =================================================================== --- gen/gen-private.h (revision 267610) +++ gen/gen-private.h (working copy) @@ -48,7 +48,6 @@ char *dd_buf; /* data buffer */ int dd_len; /* size of data buffer */ long dd_seek; /* magic cookie returned by getdirentries */ - long dd_rewind; /* magic cookie for rewinding */ int dd_flags; /* flags for readdir */ struct pthread_mutex *dd_lock; /* lock */ struct _telldir *dd_td; /* telldir position recording */ Index: gen/opendir.c =================================================================== --- gen/opendir.c (revision 267610) +++ gen/opendir.c (working copy) @@ -49,7 +49,7 @@ #include "gen-private.h" #include "telldir.h" -static DIR * __opendir_common(int, int); +static DIR * __opendir_common(int, int, long); /* * Open a directory. @@ -68,6 +68,9 @@ fdopendir(int fd) { struct stat statb; +#if 0 + off_t pos; +#endif /* Check that fd is associated with a directory. */ if (_fstat(fd, &statb) != 0) @@ -78,7 +81,20 @@ } if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) return (NULL); - return (__opendir_common(fd, DTF_HIDEW|DTF_NODUP)); +#if 0 + pos = lseek(fd, 0, SEEK_CUR); + if (pos == -1) + return (NULL); + return (__opendir_common(fd, DTF_HIDEW|DTF_NODUP, pos)); +#else + + /* + * Pass an initial seek point of -1 to indicate to telldir() + * that an lseek() is required to determine the current + * position. + */ + return (__opendir_common(fd, DTF_HIDEW|DTF_NODUP, -1)); +#endif } DIR * @@ -92,7 +108,7 @@ O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC)) == -1) return (NULL); - dir = __opendir_common(fd, flags); + dir = __opendir_common(fd, flags, 0); if (dir == NULL) { saved_errno = errno; _close(fd); @@ -113,7 +129,7 @@ * Common routine for opendir(3), __opendir2(3) and fdopendir(3). */ static DIR * -__opendir_common(int fd, int flags) +__opendir_common(int fd, int flags, long seek) { DIR *dirp; int incr; @@ -292,7 +308,7 @@ dirp->dd_buf = malloc(dirp->dd_len); if (dirp->dd_buf == NULL) goto fail; - dirp->dd_seek = 0; + dirp->dd_seek = seek; } dirp->dd_loc = 0; @@ -300,11 +316,6 @@ dirp->dd_flags = flags; dirp->dd_lock = NULL; - /* - * Set up seek point for rewinddir. - */ - dirp->dd_rewind = telldir(dirp); - return (dirp); fail: Index: gen/rewinddir.c =================================================================== --- gen/rewinddir.c (revision 267610) +++ gen/rewinddir.c (working copy) @@ -33,9 +33,14 @@ #include __FBSDID("$FreeBSD$"); +#include "namespace.h" #include #include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" #include "gen-private.h" #include "telldir.h" @@ -44,6 +49,13 @@ DIR *dirp; { - _seekdir(dirp, dirp->dd_rewind); - dirp->dd_rewind = telldir(dirp); + if (__isthreaded) + _pthread_mutex_lock(&dirp->dd_lock); + if (dirp->dd_seek != 0) { + (void) lseek(dirp->dd_fd, 0, SEEK_SET); + dirp->dd_seek = 0; + } + dirp->dd_loc = 0; + if (__isthreaded) + _pthread_mutex_unlock(&dirp->dd_lock); } Index: gen/telldir.c =================================================================== --- gen/telldir.c (revision 267610) +++ gen/telldir.c (working copy) @@ -66,6 +66,10 @@ return (-1); if (__isthreaded) _pthread_mutex_lock(&dirp->dd_lock); +#if 1 + if (dirp->dd_seek == -1) + dirp->dd_seek = lseek(dirp->dd_fd, 0, SEEK_CUR); +#endif lp->loc_index = dirp->dd_td->td_loccnt++; lp->loc_seek = dirp->dd_seek; lp->loc_loc = dirp->dd_loc;