This is the mail archive of the cygwin-developers@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

rewinddir() does not work with cygwin-1.1.5-7



This example bombs out in the first readdir() following
a rewinddir():

#include <sys/types.h>
#include <dirent.h>

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






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]