From: Paul Eggert Date: Wed, 29 Oct 2025 04:15:11 +0000 (-0700) Subject: openat2: port O_TMPFILE check to non-GNU/Linux X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6502cda83752ff2235d2064c213e7a9e2214201;p=thirdparty%2Fgnulib.git openat2: port O_TMPFILE check to non-GNU/Linux * lib/openat2.c (openat2): Don’t assume !!(O_TMPFILE & O_DIRECTORY). Although true on GNU/Linux, it is a hack and might not be true on other systems such as Cygwin. --- diff --git a/ChangeLog b/ChangeLog index 3ccd074a4c..b475160780 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2025-10-28 Paul Eggert + openat2: port O_TMPFILE check to non-GNU/Linux + * lib/openat2.c (openat2): Don’t assume !!(O_TMPFILE & O_DIRECTORY). + Although true on GNU/Linux, it is a hack and might not be true on + other systems such as Cygwin. + openat2-tests: port to FreeBSD, NetBSD Problem reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2025-10/msg00117.html diff --git a/lib/openat2.c b/lib/openat2.c index ba5f579716..ee64d05836 100644 --- a/lib/openat2.c +++ b/lib/openat2.c @@ -512,13 +512,11 @@ openat2 (int dfd, char const *filename, | O_NOLINK | O_NOLINKS | O_NONBLOCK | O_NOTRANS | O_RSYNC | O_SYNC | O_TEXT | O_TMPFILE | O_TRUNC | O_TTY_INIT)))) - | ((how->flags & (O_DIRECTORY | O_CREAT)) - == (O_DIRECTORY | O_CREAT)) + | (!!(how->flags & O_CREAT) + & !!(how->flags & (O_DIRECTORY | O_TMPFILE))) | (!!(how->flags & O_TMPFILE & ~O_DIRECTORY) - & ((how->flags & (O_ACCMODE | O_DIRECTORY)) - != (O_WRONLY | O_DIRECTORY)) - & ((how->flags & (O_ACCMODE | O_DIRECTORY)) - != (O_RDWR | O_DIRECTORY))) + & ((how->flags & (O_ACCMODE | O_PATH)) != O_WRONLY) + & ((how->flags & (O_ACCMODE | O_PATH)) != O_RDWR)) | (how->mode & ~ (how->flags & (O_CREAT | (O_TMPFILE & ~O_DIRECTORY)) ? (S_ISUID | S_ISGID | S_ISVTX