From ed2eb31da97331234bb12d70c1c16cae707d7f97 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 1 Apr 2023 02:46:22 +0200 Subject: [PATCH] test: Fix closefrom() test on macOS On macOS we do not close the file descriptors, and instead mark them all as close-on-exec. So checking whether they are not valid does not work. --- test/closefrom.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/closefrom.c b/test/closefrom.c index aa8d3b2..474c69f 100644 --- a/test/closefrom.c +++ b/test/closefrom.c @@ -55,7 +55,19 @@ main(int argc, char *argv[]) closefrom(4); for (i = 4; i < fd_max; i++) { - assert(fcntl(i, F_GETFL) == -1 && errno == EBADF); + int rc; + + errno = 0; + rc = fcntl(i, F_GETFD); +#ifdef __APPLE__ + /* On macOS we only set close-on-exec. */ + if ((i & (i - 1)) == 0) + assert(rc == FD_CLOEXEC); + else + assert(rc == -1 && errno == EBADF); +#else + assert(rc == -1 && errno == EBADF); +#endif } assert(fcntl(fd, F_GETFL) == -1 && errno == EBADF); -- 2.47.3