]> sourceware.org Git - newlib-cygwin.git/commitdiff
* fhandler_disk_file.cc (num_entries): Take . and .. into account if they do
authorChristopher Faylor <me@cgf.cx>
Wed, 10 Sep 2003 20:16:00 +0000 (20:16 +0000)
committerChristopher Faylor <me@cgf.cx>
Wed, 10 Sep 2003 20:16:00 +0000 (20:16 +0000)
not exist since cygwin simulates them.
(fhandler_cygdrive::fstat): Ditto.
(fhandler_cygdrive::readdir): Don't do any specific tests on __d_position when
seeing if a drive exists.

winsup/cygwin/ChangeLog
winsup/cygwin/dir.cc
winsup/cygwin/fhandler_disk_file.cc

index 023e63883bab5d09ac1e16888718d693257ab626..ad7010b1440c592d429e415994cc8637bccbb489 100644 (file)
@@ -1,3 +1,11 @@
+2003-09-10  Christopher Faylor  <cgf@redhat.com>
+
+       * fhandler_disk_file.cc (num_entries): Take .  and ..  into account if
+       they do not exist since cygwin simulates them.
+       (fhandler_cygdrive::fstat): Ditto.
+       (fhandler_cygdrive::readdir): Don't do any specific tests on
+       __d_position when seeing if a drive exists.
+
 2003-09-10  Corinna Vinschen  <corinna@vinschen.de>
 
        * Makefile.in (DLL_OFILES): Add getopt.o and iruserok.o.
index c7edd887146d1e5a487ff44972ef13aa8d2cd9ff..96ab1f282bb50aceb2aaed42625dada0c08be192 100644 (file)
@@ -129,12 +129,14 @@ readdir (DIR *dir)
          res = dir->__d_dirent;
          strcpy (res->d_name, ".");
          dir->__flags |= opendir_saw_dot;
+         dir->__d_position++;
        }
       else if (!(dir->__flags & opendir_saw_dot_dot))
        {
          res = dir->__d_dirent;
          strcpy (res->d_name, "..");
          dir->__flags |= opendir_saw_dot_dot;
+         dir->__d_position++;
        }
     }
 
index e687efc63c4f895f69dbc3bff5a2f010ecdd1767..5dbfa457bde38d482ef951ba46745d3f5acfaa7d 100644 (file)
@@ -48,14 +48,18 @@ num_entries (const char *win32_name)
 
   if (handle == INVALID_HANDLE_VALUE)
     return 2; /* 2 is the minimum number of links to a dir, so... */
-  count ++;
+  int saw_dot = 2;
   while (FindNextFileA (handle, &buf))
     {
-      if ((buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
-       count ++;
+      if (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+       count++;
+      if (buf.cFileName[0] == '.'
+         && (buf.cFileName[1] == '\0'
+             || (buf.cFileName[1] == '.' && buf.cFileName[2] == '\0')))
+       saw_dot--;
     }
   FindClose (handle);
-  return count;
+  return count + saw_dot;
 }
 
 int __stdcall
@@ -743,7 +747,7 @@ fhandler_cygdrive::fstat (struct __stat64 *buf, path_conv *pc)
   buf->st_mode = S_IFDIR | 0555;
   if (!ndrives)
     set_drives ();
-  buf->st_nlink = ndrives;
+  buf->st_nlink = ndrives + 2;
   return 0;
 }
 
@@ -766,19 +770,14 @@ fhandler_cygdrive::readdir (DIR *dir)
     return fhandler_disk_file::readdir (dir);
   if (!pdrive || !*pdrive)
     return NULL;
-  else if (dir->__d_position > 1
-          && GetFileAttributes (pdrive) == INVALID_FILE_ATTRIBUTES)
+  if (GetFileAttributes (pdrive) == INVALID_FILE_ATTRIBUTES)
     {
       pdrive = strchr (pdrive, '\0') + 1;
       return readdir (dir);
     }
-  else if (*pdrive == '.')
-    strcpy (dir->__d_dirent->d_name, pdrive);
-  else
-    {
-      *dir->__d_dirent->d_name = cyg_tolower (*pdrive);
-      dir->__d_dirent->d_name[1] = '\0';
-    }
+
+  *dir->__d_dirent->d_name = cyg_tolower (*pdrive);
+  dir->__d_dirent->d_name[1] = '\0';
   dir->__d_position++;
   pdrive = strchr (pdrive, '\0') + 1;
   syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
This page took 0.039319 seconds and 5 git commands to generate.