diff options
author | Christopher Faylor <me@cgf.cx> | 2002-06-01 02:45:38 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2002-06-01 02:45:38 +0000 |
commit | 28af03faed3f79e2d8e284f1fc83adb6a0c4f193 (patch) | |
tree | df5520d12016cbf330bddfdb9f832efd80486be9 | |
parent | 548e208b82268e8d4411a0ca6fc3424046cdd9a9 (diff) | |
download | newlib-28af03faed3f79e2d8e284f1fc83adb6a0c4f193.zip newlib-28af03faed3f79e2d8e284f1fc83adb6a0c4f193.tar.gz newlib-28af03faed3f79e2d8e284f1fc83adb6a0c4f193.tar.bz2 |
* fhandler_disk_file.cc (readdir): Move inode calculation into caller.
(fhandler_cygdrive::readdir): Add "." and "..".
* dir.cc (readdir): Move inode calculation here so that fhandler readdirs can
benefit.
-rw-r--r-- | winsup/cygwin/ChangeLog | 7 | ||||
-rw-r--r-- | winsup/cygwin/dir.cc | 37 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_disk_file.cc | 50 |
3 files changed, 59 insertions, 35 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 02fedb8..13d79a7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,12 @@ 2002-05-31 Christopher Faylor <cgf@redhat.com> + * fhandler_disk_file.cc (readdir): Move inode calculation into caller. + (fhandler_cygdrive::readdir): Add "." and "..". + * dir.cc (readdir): Move inode calculation here so that fhandler + readdirs can benefit. + +2002-05-31 Christopher Faylor <cgf@redhat.com> + * fhandler_console.cc (fhandler_console::open): Reinstate setting of flags. diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index ef8b67d..94e2802 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -113,7 +113,42 @@ readdir (DIR *dir) return NULL; } - return ((fhandler_base *) dir->__d_u.__d_data.__fh)->readdir (dir); + dirent *res = ((fhandler_base *) dir->__d_u.__d_data.__fh)->readdir (dir); + + if (res) + { + /* Compute d_ino by combining filename hash with the directory hash + (which was stored in dir->__d_dirhash when opendir was called). */ + if (res->d_name[0] == '.') + { + if (res->d_name[1] == '\0') + dir->__d_dirent->d_ino = dir->__d_dirhash; + else if (res->d_name[1] != '.' || res->d_name[2] != '\0') + goto hashit; + else + { + char *p, up[strlen (dir->__d_dirname) + 1]; + strcpy (up, dir->__d_dirname); + if (!(p = strrchr (up, '\\'))) + goto hashit; + *p = '\0'; + if (!(p = strrchr (up, '\\'))) + dir->__d_dirent->d_ino = hash_path_name (0, "."); + else + { + *p = '\0'; + dir->__d_dirent->d_ino = hash_path_name (0, up); + } + } + } + else + { + hashit: + ino_t dino = hash_path_name (dir->__d_dirhash, "\\"); + dir->__d_dirent->d_ino = hash_path_name (dino, res->d_name); + } + } + return res; } extern "C" __off64_t diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 2548ce6..54c08ec 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -656,37 +656,6 @@ fhandler_disk_file::readdir (DIR *dir) } } - /* Compute d_ino by combining filename hash with the directory hash - (which was stored in dir->__d_dirhash when opendir was called). */ - if (buf.cFileName[0] == '.') - { - if (buf.cFileName[1] == '\0') - dir->__d_dirent->d_ino = dir->__d_dirhash; - else if (buf.cFileName[1] != '.' || buf.cFileName[2] != '\0') - goto hashit; - else - { - char *p, up[strlen (dir->__d_dirname) + 1]; - strcpy (up, dir->__d_dirname); - if (!(p = strrchr (up, '\\'))) - goto hashit; - *p = '\0'; - if (!(p = strrchr (up, '\\'))) - dir->__d_dirent->d_ino = hash_path_name (0, "."); - else - { - *p = '\0'; - dir->__d_dirent->d_ino = hash_path_name (0, up); - } - } - } - else - { - hashit: - ino_t dino = hash_path_name (dir->__d_dirhash, "\\"); - dir->__d_dirent->d_ino = hash_path_name (dino, buf.cFileName); - } - dir->__d_position++; res = dir->__d_dirent; syscall_printf ("%p = readdir (%p) (%s)", @@ -784,13 +753,26 @@ fhandler_cygdrive::readdir (DIR *dir) set_errno (ENMFILE); return NULL; } - if (GetFileAttributes (pdrive) == INVALID_FILE_ATTRIBUTES) + if (dir->__d_position == 0) + { + *dir->__d_dirent->d_name = '.'; + dir->__d_dirent->d_name[1] = '\0'; + } + else if (dir->__d_position == 1) + { + dir->__d_dirent->d_name[0] = dir->__d_dirent->d_name[1] = '.'; + dir->__d_dirent->d_name[2] = '\0'; + } + else if (GetFileAttributes (pdrive) == INVALID_FILE_ATTRIBUTES) { pdrive += DRVSZ; return readdir (dir); } - *dir->__d_dirent->d_name = cyg_tolower (*pdrive); - dir->__d_dirent->d_name[1] = '\0'; + else + { + *dir->__d_dirent->d_name = cyg_tolower (*pdrive); + dir->__d_dirent->d_name[1] = '\0'; + } dir->__d_position++; pdrive += DRVSZ; syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir, |