]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
test: Fix closefrom() test on macOS
authorGuillem Jover <guillem@hadrons.org>
Sat, 1 Apr 2023 00:46:22 +0000 (02:46 +0200)
committerGuillem Jover <guillem@hadrons.org>
Mon, 17 Apr 2023 02:12:42 +0000 (04:12 +0200)
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

index aa8d3b28b5b250ace8bb4e3612aebc6604d73182..474c69f65409d2fedd9d332915cb5973bdcc2711 100644 (file)
@@ -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);