diff options
author | Roland McGrath <roland@gnu.org> | 2005-02-16 10:43:02 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 2005-02-16 10:43:02 +0000 |
commit | ecaab38901590f7ee9a1b44fd852c25ba15b4434 (patch) | |
tree | 5257c5c9b6029d921057f5aacd6d6a5c372245bd | |
parent | ca0a2bd89438d7495ac50ed6adf8e15f54cffafe (diff) | |
download | glibc-ecaab38901590f7ee9a1b44fd852c25ba15b4434.tar.gz glibc-ecaab38901590f7ee9a1b44fd852c25ba15b4434.tar.xz glibc-ecaab38901590f7ee9a1b44fd852c25ba15b4434.zip |
2005-01-16 GOTO Masanori <gotom@debian.or.jp>
[BZ #734] * sysdeps/unix/rewinddir.c: Reset filepos. * dirent/tst-seekdir.c: Check telldir value after calling rewinddir.
-rw-r--r-- | dirent/tst-seekdir.c | 28 | ||||
-rw-r--r-- | sysdeps/unix/rewinddir.c | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/dirent/tst-seekdir.c b/dirent/tst-seekdir.c index b833c30705..43808fecb5 100644 --- a/dirent/tst-seekdir.c +++ b/dirent/tst-seekdir.c @@ -11,8 +11,23 @@ main (int argc, char *argv[]) int i = 0; int result = 0; struct dirent *dp; + long int save0; + long int rewind; dirp = opendir ("."); + if (dirp == NULL) + { + printf ("opendir failed: %m\n"); + return 1; + } + + save0 = telldir (dirp); + if (save0 == -1) + { + printf ("telldir failed: %m\n"); + result = 1; + } + for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp)) { /* save position 3 (after fourth entry) */ @@ -44,6 +59,19 @@ main (int argc, char *argv[]) for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp)) printf ("%s\n", dp->d_name); + /* Check rewinddir */ + rewinddir (dirp); + rewind = telldir (dirp); + if (rewind == -1) + { + printf ("telldir failed: %m\n"); + result = 1; + } + else if (save0 != rewind) + { + printf ("rewinddir didn't reset directory stream\n"); + result = 1; + } closedir (dirp); return result; diff --git a/sysdeps/unix/rewinddir.c b/sysdeps/unix/rewinddir.c index 9f3724fc6a..cb0f52079a 100644 --- a/sysdeps/unix/rewinddir.c +++ b/sysdeps/unix/rewinddir.c @@ -30,6 +30,7 @@ rewinddir (dirp) { __libc_lock_lock (dirp->lock); (void) __lseek (dirp->fd, (off_t) 0, SEEK_SET); + dirp->filepos = 0; dirp->offset = 0; dirp->size = 0; __libc_lock_unlock (dirp->lock); |