From 221f2898b9140b4cc103d2c485061023706c1fcf Mon Sep 17 00:00:00 2001 From: Nicolas Cavallari Date: Wed, 7 Apr 2021 19:08:23 +0200 Subject: open: Add support for O_TMPFILE Since Linux 3.11, O_TMPFILE allows to create unnamed files that can be linked later on. It is internally defined as (O_TMPFILE | O_DIRECTORY) to make it fail on old kernels. Copying definitions from glibc for O_TMPFILE is not enough to support O_TMPFILE; The open() wrapper also need to pass the mode when the flag contains O_TMPFILE, otherwise, it will pass mode 000 which will succeed but yield unexpected results. openat() is curiously not affected since it passes the mode unconditionally.. Signed-off-by: Nicolas Cavallari --- libc/sysdeps/linux/common/open.c | 2 +- libc/sysdeps/linux/common/open64.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'libc/sysdeps/linux/common') diff --git a/libc/sysdeps/linux/common/open.c b/libc/sysdeps/linux/common/open.c index ccdcf3848..ac09d40f0 100644 --- a/libc/sysdeps/linux/common/open.c +++ b/libc/sysdeps/linux/common/open.c @@ -31,7 +31,7 @@ int open(const char *file, int oflag, ...) int oldtype, result; #endif - if (oflag & O_CREAT) { + if (oflag & (O_CREAT | (O_TMPFILE &~ O_DIRECTORY))) { va_list arg; va_start(arg, oflag); mode = va_arg(arg, mode_t); diff --git a/libc/sysdeps/linux/common/open64.c b/libc/sysdeps/linux/common/open64.c index 6e65a988e..9d4c06b18 100644 --- a/libc/sysdeps/linux/common/open64.c +++ b/libc/sysdeps/linux/common/open64.c @@ -10,13 +10,13 @@ #include #include -/* Open FILE with access OFLAG. If OFLAG includes O_CREAT, +/* Open FILE with access OFLAG. If OFLAG includes O_CREAT or O_TMPFILE, a third argument is the file protection. */ int open64(const char *file, int oflag, ...) { mode_t mode = 0; - if (oflag & O_CREAT) { + if (oflag & (O_CREAT | (O_TMPFILE &~ O_DIRECTORY))) { va_list arg; va_start (arg, oflag); mode = va_arg (arg, mode_t); -- cgit v1.2.3