Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-developers-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin-developers AT sources DOT redhat DOT com Message-Id: <200011141213.MAA49910@mailhost1.dircon.co.uk> Date: Tue, 14 Nov 2000 13:14:10 +0100 To: cygwin-developers AT sources DOT redhat DOT com Subject: rewinddir() does not work with cygwin-1.1.5-7 From: X-Mailer: Webmail 1.0.1 This example bombs out in the first readdir() following a rewinddir(): #include #include main() { DIR *dirp; struct dirent *dp; dirp = opendir("."); while((dp = readdir(dirp)) != NULL) printf("1: %s\n", dp->d_name); rewinddir(dirp); while((dp = readdir(dirp)) != NULL) printf("2: %s\n", dp->d_name); closedir(dirp); } Program received signal SIGSEGV, Segmentation fault. 0x77f674cb in ?? () (gdb) where #0 0x77f674cb in ?? () #1 0x77f0c579 in ?? () #2 0x61004910 in readdir (dir=0xa01a4e8) at ../../../../winsup/cygwin/dir.cc:160 #3 0x4010c8 in main () at readdir.c:16 #4 0x61003617 in dll_crt0_1 () at ../../../../winsup/cygwin/dcrt0.cc:852 #5 0x610038a5 in _dll_crt0 () at ../../../../winsup/cygwin/dcrt0.cc:927 #6 0x610038e4 in dll_crt0 (uptr=0x0) at ../../../../winsup/cygwin/dcrt0.cc:939 #7 0x401153 in cygwin_crt0 () After the Nov-9 dir.cc patch, an implicit rewind after hitting the end of a directory disappeared and the current rewinddir() code only resets __d_position = 0, if the directory handle is currently open. This seems to fix the problem: --- dir.cc- Thu Nov 9 17:52:40 2000 +++ dir.cc Tue Nov 14 11:35:41 2000 @@ -244,8 +244,8 @@ rewinddir (DIR * dir) { (void) FindClose (dir->__d_u.__d_data.__handle); dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE; - dir->__d_position = 0; } + dir->__d_position = 0; } /* closedir: POSIX 5.1.2.1 */ ChangeLog: * dir.cc (rewinddir): Always set __d_position = 0, so next call to readdir() will restart the directory scan. Thanks, Eric Fifer