From d72be712aa1e88f20a2cc0606c6d7b0928923848 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 23 Jan 2024 13:41:14 +0100 Subject: [PATCH] Cygwin: implement fdclosedir fdclosedir is BSD-only but already present in dirent.h for a couple of years. Signed-off-by: Corinna Vinschen --- 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 4539496d1..049be4cd0 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 2e0f03b90..82797a41f 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 ceff10115..e21e04add 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 6b0ec5dbc..fe933d8c7 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: ------------- -- 2.43.5