From a71aee46c41636e75325df62d9027bfc66b3c4dc Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 3 Sep 2001 16:36:54 +0000 Subject: [PATCH] * cygwin.din: Add `dirfd'. * dir.cc (dirfd): New function. (opendir): Open a directory file descriptor and save it in __d_dirent->d_fd. (closedir): Close directory file descriptor. * include/cygwin/version.h: Bump API minor version to 44. --- winsup/cygwin/ChangeLog | 9 +++++++++ winsup/cygwin/cygwin.din | 2 ++ winsup/cygwin/dir.cc | 17 +++++++++++++++++ winsup/cygwin/include/cygwin/version.h | 3 ++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 167457d31..809f49ad3 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +Mon Sep 3 18:34:00 2001 Corinna Vinschen + + * cygwin.din: Add `dirfd'. + * dir.cc (dirfd): New function. + (opendir): Open a directory file descriptor and save it in + __d_dirent->d_fd. + (closedir): Close directory file descriptor. + * include/cygwin/version.h: Bump API minor version to 44. + Sun Sep 2 22:09:31 2001 Christopher Faylor * child_info.h: Modify magic number. diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 10ddbbf7b..693b16bdc 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -130,6 +130,8 @@ difftime _difftime = difftime div _div = div +dirfd +_dirfd = dirfd _dll_crt0@0 dll_crt0__FP11per_process cygwin_dll_init diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index 83e38deb5..d44615e58 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -9,6 +9,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" +#include #include #include #include @@ -61,6 +62,18 @@ writable_directory (const char *file) #endif } +extern "C" int +dirfd (DIR *dir) +{ + if (dir->__d_cookie != __DIRENT_COOKIE) + { + set_errno (EBADF); + syscall_printf ("-1 = dirfd (%p)", dir); + return -1; + } + return dir->__d_dirent->d_fd; +} + /* opendir: POSIX 5.1.2.1 */ extern "C" DIR * opendir (const char *dirname) @@ -114,6 +127,7 @@ opendir (const char *dirname) goto failed; } strcpy (dir->__d_dirname, real_dirname.get_win32 ()); + dir->__d_dirent->d_fd = open (dir->__d_dirname, O_RDONLY | O_DIROPEN); /* FindFirstFile doesn't seem to like duplicate /'s. */ len = strlen (dir->__d_dirname); if (len == 0 || SLASH_P (dir->__d_dirname[len - 1])) @@ -290,6 +304,9 @@ closedir (DIR * dir) return -1; } + if (dir->__d_dirent->d_fd >= 0) + close (dir->__d_dirent->d_fd); + /* Reset the marker in case the caller tries to use `dir' again. */ dir->__d_cookie = 0; diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index db9a97ba0..f270a82d0 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -141,10 +141,11 @@ details. */ 41: __signgam 42: sys_errlist, sys_nerr 43: sigsetjmp, siglongjmp fixed + 44: Export dirfd */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 43 +#define CYGWIN_VERSION_API_MINOR 44 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible