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: <3A11634E.C89DEBF3@redhat.com> Date: Tue, 14 Nov 2000 17:07:42 +0100 From: Corinna Vinschen Reply-To: cygwin-developers AT sources DOT redhat DOT com X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.14-SMP i686) X-Accept-Language: de, en MIME-Version: 1.0 To: cygdev Subject: Re: rewinddir() does not work with cygwin-1.1.5-7 References: <200011141213 DOT MAA49910 AT mailhost1 DOT dircon DOT co DOT uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eric, Patch applied. Thank you, Corinna efifer AT dircon DOT co DOT uk wrote: > > 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 -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Developer mailto:cygwin AT sources DOT redhat DOT com Red Hat, Inc. mailto:vinschen AT redhat DOT com