Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2005-08-20 10:19:55 +0400
committerChristopher Faylor <me@cgf.cx>2005-08-20 10:19:55 +0400
commitd9a227643589484cfccd75174482a7f2e96f49d5 (patch)
tree9538a97eb6010b3ddca0b89e6bec28be2351258a /winsup/cygwin/dir.cc
parent683ef953925b1d05e49bd9e75147ebc02e9cb82c (diff)
* cygerrno.h (geterrno_from_win_error): Change declaration to default to using
GetLastError and EACCESS. * cygwin.din: Export readdir_r. * include/cygwin/version.h: Bump API version number to 138. * syscalls.cc (readdir_worker): New function, renamed from old readdir() function. (readdir): Use readdir_worker. (readdir_r): New function. * fhandler.h (fhandler_base::readdir): Accommodate second argument indicating dirent buffer. (fhandler_disk_file::readdir): Ditto. (fhandler_cygdrive::readdir): Ditto. (fhandler_proc::readdir): Ditto. (fhandler_netdrive::readdir): Ditto. (fhandler_registry::readdir): Ditto. (fhandler_process::readdir): Ditto. * fhandler.cc (fhandler_base::readdir): Ditto. * fhandler_disk_file.cc (fhandler_disk_file::readdir): Ditto. * fhandler_cygdrive.cc (fhandler_cygdrive::readdir): Ditto. * fhandler_proc.cc (fhandler_proc::readdir): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::readdir): Ditto. * fhandler_registry.cc (fhandler_registry::readdir): Ditto. * fhandler_process.cc (fhandler_process::readdir): Ditto.
Diffstat (limited to 'winsup/cygwin/dir.cc')
-rw-r--r--winsup/cygwin/dir.cc69
1 files changed, 47 insertions, 22 deletions
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index 894691d8f..ca9ff5979 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -65,53 +65,51 @@ opendir (const char *name)
return res;
}
-/* readdir: POSIX 5.1.2.1 */
-extern "C" struct dirent *
-readdir (DIR *dir)
+int
+readdir_worker (DIR *dir, dirent *de)
{
myfault efault;
- if (efault.faulted (EFAULT))
- return NULL;
+ if (efault.faulted ())
+ return EFAULT;
if (dir->__d_cookie != __DIRENT_COOKIE)
{
- set_errno (EBADF);
syscall_printf ("%p = readdir (%p)", NULL, dir);
- return NULL;
+ return EBADF;
}
- dirent *res = ((fhandler_base *) dir->__fh)->readdir (dir);
+ int res = ((fhandler_base *) dir->__fh)->readdir (dir, de);
- if (!res)
+ if (res)
{
if (!(dir->__flags & dirent_saw_dot))
{
- res = dir->__d_dirent;
- strcpy (res->d_name, ".");
+ strcpy (de->d_name, ".");
dir->__flags |= dirent_saw_dot;
dir->__d_position++;
+ res = 0;
}
else if (!(dir->__flags & dirent_saw_dot_dot))
{
- res = dir->__d_dirent;
- strcpy (res->d_name, "..");
+ strcpy (de->d_name, "..");
dir->__flags |= dirent_saw_dot_dot;
dir->__d_position++;
+ res = 0;
}
}
- if (res)
+ 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 (de->d_name[0] == '.')
{
- if (res->d_name[1] == '\0')
+ if (de->d_name[1] == '\0')
{
- dir->__d_dirent->d_ino = dir->__d_dirhash;
+ de->d_ino = dir->__d_dirhash;
dir->__flags |= dirent_saw_dot;
}
- else if (res->d_name[1] != '.' || res->d_name[2] != '\0')
+ else if (de->d_name[1] != '.' || de->d_name[2] != '\0')
goto hashit;
else
{
@@ -122,11 +120,11 @@ readdir (DIR *dir)
goto hashit;
*p = '\0';
if (!(p = strrchr (up, '\\')))
- dir->__d_dirent->d_ino = hash_path_name (0, ".");
+ de->d_ino = hash_path_name (0, ".");
else
{
*p = '\0';
- dir->__d_dirent->d_ino = hash_path_name (0, up);
+ de->d_ino = hash_path_name (0, up);
}
}
}
@@ -134,9 +132,36 @@ readdir (DIR *dir)
{
hashit:
__ino64_t dino = hash_path_name (dir->__d_dirhash, "\\");
- dir->__d_dirent->d_ino = hash_path_name (dino, res->d_name);
+ de->d_ino = hash_path_name (dino, de->d_name);
}
- res->__ino32 = dir->__d_dirent->d_ino; // for legacy applications
+ de->__ino32 = de->d_ino; // for legacy applications
+ }
+ return res;
+}
+
+/* readdir: POSIX 5.1.2.1 */
+extern "C" struct dirent *
+readdir (DIR *dir)
+{
+ int res = readdir_worker (dir, dir->__d_dirent);
+ if (res == 0)
+ return dir->__d_dirent;
+ if (res != ENMFILE)
+ set_errno (res);
+ return NULL;
+}
+
+extern "C" int
+readdir_r (DIR *dir, dirent *de, dirent **ode)
+{
+ int res = readdir_worker (dir, de);
+ if (!res)
+ *ode = de;
+ else
+ {
+ *ode = NULL;
+ if (res != ENMFILE)
+ res = 0;
}
return res;
}