public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: implement fdclosedir
@ 2024-02-01 11:39 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2024-02-01 11:39 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d72be712aa1e88f20a2cc0606c6d7b0928923848

commit d72be712aa1e88f20a2cc0606c6d7b0928923848
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Jan 23 13:41:14 2024 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Jan 31 20:11:57 2024 +0100

    Cygwin: implement fdclosedir
    
    fdclosedir is BSD-only but already present in dirent.h for a couple
    of years.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/cygwin.din               |  1 +
 winsup/cygwin/dir.cc                   | 34 ++++++++++++++++++++++++++++------
 winsup/cygwin/include/cygwin/version.h |  3 ++-
 winsup/cygwin/release/3.6.0            |  2 ++
 4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din
index 4539496d19cb..049be4cd0377 100644
--- a/winsup/cygwin/cygwin.din
+++ b/winsup/cygwin/cygwin.din
@@ -520,6 +520,7 @@ fcvt SIGFE
 fcvtbuf SIGFE
 fcvtf SIGFE
 fdatasync SIGFE
+fdclosedir SIGFE
 fdim NOSIGFE
 fdimf NOSIGFE
 fdiml NOSIGFE
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index 2e0f03b902c0..82797a41f4c1 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -267,9 +267,8 @@ rewinddir (DIR *dir)
   __endtry
 }
 
-/* closedir: POSIX 5.1.2.1 */
-extern "C" int
-closedir (DIR *dir)
+static int
+closedir_worker (DIR *dir, int *fdret)
 {
   __try
     {
@@ -280,21 +279,44 @@ closedir (DIR *dir)
 
 	  int res = ((fhandler_base *) dir->__fh)->closedir (dir);
 
-	  close (dir->__d_fd);
+	  if (fdret)
+	    *fdret = dir->__d_fd;
+	  else
+	    close (dir->__d_fd);
+
 	  free (dir->__d_dirname);
 	  free (dir->__d_dirent);
 	  free (dir);
-	  syscall_printf ("%R = closedir(%p)", res, dir);
 	  return res;
 	}
       set_errno (EBADF);
     }
   __except (EFAULT) {}
   __endtry
-  syscall_printf ("%R = closedir(%p)", -1, dir);
   return -1;
 }
 
+/* closedir: POSIX 5.1.2.1 */
+extern "C" int
+closedir (DIR *dir)
+{
+  int res;
+
+  res = closedir_worker (dir, NULL);
+  syscall_printf ("%R = closedir(%p)", res, dir);
+  return res;
+}
+
+extern "C" int
+fdclosedir (DIR *dir)
+{
+  int fd = -1;
+
+  closedir_worker (dir, &fd);
+  syscall_printf ("%d = fdclosedir(%p)", fd, dir);
+  return fd;
+}
+
 /* mkdir: POSIX 5.4.1.1 */
 extern "C" int
 mkdir (const char *dir, mode_t mode)
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index ceff10115aad..e21e04addd8c 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -487,12 +487,13 @@ details. */
   350: Add close_range.
   351: Add getlocalename_l.
   352: Implement dirent.d_reclen.
+  353: Implement fdclosedir.
 
   Note that we forgot to bump the api for ualarm, strtoll, strtoull,
   sigaltstack, sethostname. */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 352
+#define CYGWIN_VERSION_API_MINOR 353
 
 /* There is also a compatibity version number associated with the shared memory
    regions.  It is incremented when incompatible changes are made to the shared
diff --git a/winsup/cygwin/release/3.6.0 b/winsup/cygwin/release/3.6.0
index 6b0ec5dbce3a..fe933d8c74cc 100644
--- a/winsup/cygwin/release/3.6.0
+++ b/winsup/cygwin/release/3.6.0
@@ -3,6 +3,8 @@ What's new:
 
 - New API call: getlocalename_l.
 
+- New API call: fdclosedir.
+
 
 What changed:
 -------------

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-01 11:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01 11:39 [newlib-cygwin/main] Cygwin: implement fdclosedir Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).