public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: implement fdclosedir
Date: Thu,  1 Feb 2024 11:39:13 +0000 (GMT)	[thread overview]
Message-ID: <20240201113913.C0AFD38582BE@sourceware.org> (raw)

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:
 -------------

                 reply	other threads:[~2024-02-01 11:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240201113913.C0AFD38582BE@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).