@@ -20,8 +20,8 @@
# error "Never include <bits/fcntl2.h> directly; use <fcntl.h> instead."
#endif
-/* Check that calls to open and openat with O_CREAT set have an
- appropriate third/fourth parameter. */
+/* Check that calls to open and openat have an appropriate third/fourth
+ parameter. */
#ifndef __USE_FILE_OFFSET64
extern int __open_2 (const char *__path, int __oflag) __nonnull ((1));
extern int __REDIRECT (__open_alias, (const char *__path, int __oflag, ...),
@@ -35,7 +35,7 @@ extern int __REDIRECT (__open_alias, (const char *__path, int __oflag, ...),
__errordecl (__open_too_many_args,
"open can be called either with 2 or 3 arguments, not more");
__errordecl (__open_missing_mode,
- "open with O_CREAT in second argument needs 3 arguments");
+ "open with e.g. O_CREAT in second argument needs 3 arguments");
__fortify_function int
open (const char *__path, int __oflag, ...)
@@ -45,7 +45,7 @@ open (const char *__path, int __oflag, ...)
if (__builtin_constant_p (__oflag))
{
- if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
+ if (__OPEN_NEEDS_MODE(__oflag) && __va_arg_pack_len () < 1)
{
__open_missing_mode ();
return __open_2 (__path, __oflag);
@@ -67,7 +67,7 @@ extern int __REDIRECT (__open64_alias, (const char *__path, int __oflag,
__errordecl (__open64_too_many_args,
"open64 can be called either with 2 or 3 arguments, not more");
__errordecl (__open64_missing_mode,
- "open64 with O_CREAT in second argument needs 3 arguments");
+ "open64 with e.g. O_CREAT in second argument needs 3 arguments");
__fortify_function int
open64 (const char *__path, int __oflag, ...)
@@ -77,7 +77,7 @@ open64 (const char *__path, int __oflag, ...)
if (__builtin_constant_p (__oflag))
{
- if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
+ if (__OPEN_NEEDS_MODE(__oflag) && __va_arg_pack_len () < 1)
{
__open64_missing_mode ();
return __open64_2 (__path, __oflag);
@@ -111,7 +111,7 @@ extern int __REDIRECT (__openat_alias, (int __fd, const char *__path,
__errordecl (__openat_too_many_args,
"openat can be called either with 3 or 4 arguments, not more");
__errordecl (__openat_missing_mode,
- "openat with O_CREAT in third argument needs 4 arguments");
+ "openat with e.g. O_CREAT in third argument needs 4 arguments");
__fortify_function int
openat (int __fd, const char *__path, int __oflag, ...)
@@ -121,7 +121,7 @@ openat (int __fd, const char *__path, int __oflag, ...)
if (__builtin_constant_p (__oflag))
{
- if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
+ if (__OPEN_NEEDS_MODE(__oflag) && __va_arg_pack_len () < 1)
{
__openat_missing_mode ();
return __openat_2 (__fd, __path, __oflag);
@@ -145,7 +145,7 @@ extern int __REDIRECT (__openat64_alias, (int __fd, const char *__path,
__errordecl (__openat64_too_many_args,
"openat64 can be called either with 3 or 4 arguments, not more");
__errordecl (__openat64_missing_mode,
- "openat64 with O_CREAT in third argument needs 4 arguments");
+ "openat64 with e.g. O_CREAT in third argument needs 4 arguments");
__fortify_function int
openat64 (int __fd, const char *__path, int __oflag, ...)
@@ -155,7 +155,7 @@ openat64 (int __fd, const char *__path, int __oflag, ...)
if (__builtin_constant_p (__oflag))
{
- if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
+ if (__OPEN_NEEDS_MODE(__oflag) && __va_arg_pack_len () < 1)
{
__openat64_missing_mode ();
return __openat64_2 (__fd, __path, __oflag);
@@ -34,6 +34,10 @@ __BEGIN_DECLS
numbers and flag bits for `open', `fcntl', et al. */
#include <bits/fcntl.h>
+#ifndef __OPEN_NEEDS_MODE
+# define __OPEN_NEEDS_MODE(oflag) ( ((oflag) & O_CREAT) != 0 )
+#endif
+
/* POSIX.1-2001 specifies that these types are defined by <fcntl.h>.
Earlier POSIX standards permitted any type ending in `_t' to be defined
by any POSIX header, so we don't conditionalize the definitions here. */
@@ -160,7 +164,7 @@ typedef __pid_t pid_t;
extern int fcntl (int __fd, int __cmd, ...);
/* Open FILE and return a new file descriptor for it, or -1 on error.
- OFLAG determines the type of access used. If O_CREAT is on OFLAG,
+ OFLAG determines the type of access used. If __OPEN_NEEDS_MODE(OFLAG),
the third argument is taken as a `mode_t', the mode of the created file.
This function is a cancellation point and therefore not marked with
@@ -23,7 +23,7 @@
#include <stdio.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If __OPEN_NEEDS_MODE(OFLAG),
a third argument is the file protection. */
int
__libc_open (file, oflag)
@@ -38,7 +38,7 @@ __libc_open (file, oflag)
return -1;
}
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start(arg, oflag);
@@ -21,7 +21,7 @@
#include <stddef.h>
#include <stdio.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If __OPEN_NEEDS_MODE(OFLAG),
a third argument is the file protection. */
int
__libc_open64 (file, oflag)
@@ -36,7 +36,7 @@ __libc_open64 (file, oflag)
return -1;
}
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -22,8 +22,8 @@
int
__open64_2 (const char *file, int oflag)
{
- if (oflag & O_CREAT)
- __fortify_fail ("invalid open64 call: O_CREAT without mode");
+ if (__OPEN_NEEDS_MODE(oflag))
+ __fortify_fail ("invalid open64 call: missing mode argument");
return __open64 (file, oflag);
}
@@ -22,8 +22,8 @@
int
__open_2 (const char *file, int oflag)
{
- if (oflag & O_CREAT)
- __fortify_fail ("invalid open call: O_CREAT without mode");
+ if (__OPEN_NEEDS_MODE(oflag))
+ __fortify_fail ("invalid open call: missing mode argument");
return __open (file, oflag);
}
@@ -30,7 +30,7 @@ int __have_atfcts;
#endif
/* Open FILE with access OFLAG. Interpret relative paths relative to
- the directory associated with FD. If OFLAG includes O_CREAT, a
+ the directory associated with FD. If __OPEN_NEEDS_MODE(OFLAG), a
third argument is the file protection. */
int
__openat (fd, file, oflag)
@@ -60,7 +60,7 @@ __openat (fd, file, oflag)
}
}
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -23,7 +23,7 @@
#include <sys/stat.h>
/* Open FILE with access OFLAG. Interpret relative paths relative to
- the directory associated with FD. If OFLAG includes O_CREAT, a
+ the directory associated with FD. If __OPEN_NEEDS_MODE(OFLAG), a
third argument is the file protection. */
int
__openat64 (fd, file, oflag)
@@ -53,7 +53,7 @@ __openat64 (fd, file, oflag)
}
}
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -22,8 +22,8 @@
int
__openat64_2 (int fd, const char *file, int oflag)
{
- if (oflag & O_CREAT)
- __fortify_fail ("invalid openat64 call: O_CREAT without mode");
+ if (__OPEN_NEEDS_MODE(oflag))
+ __fortify_fail ("invalid openat64 call: missing mode argument");
return __openat64 (fd, file, oflag);
}
@@ -22,8 +22,8 @@
int
__openat_2 (int fd, const char *file, int oflag)
{
- if (oflag & O_CREAT)
- __fortify_fail ("invalid openat call: O_CREAT without mode");
+ if (__OPEN_NEEDS_MODE(oflag))
+ __fortify_fail ("invalid openat call: missing mode argument");
return __openat (fd, file, oflag);
}
@@ -22,7 +22,7 @@
#include <hurd.h>
#include <hurd/fd.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If __OPEN_NEEDS_MODE(OFLAG),
a third argument is the file protection. */
int
__libc_open (const char *file, int oflag, ...)
@@ -30,7 +30,7 @@ __libc_open (const char *file, int oflag, ...)
mode_t mode;
io_t port;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -26,7 +26,7 @@
#include <hurd/fd.h>
/* Open FILE with access OFLAG. Interpret relative paths relative to
- the directory associated with FD. If OFLAG includes O_CREAT, a
+ the directory associated with FD. If __OPEN_NEEDS_MODE(OFLAG), a
third argument is the file protection. */
int
__openat (fd, file, oflag)
@@ -37,7 +37,7 @@ __openat (fd, file, oflag)
mode_t mode;
io_t port;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -19,14 +19,14 @@
#include <stdarg.h>
#include <sysdep-cancel.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If __OPEN_NEEDS_MODE(OFLAG),
a third argument is the file protection. */
int
__libc_open64 (const char *file, int oflag, ...)
{
int mode = 0;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -100,6 +100,9 @@
# define __O_TMPFILE 020200000
#endif
+#define __OPEN_NEEDS_MODE(oflag) \
+ ( ((oflag) & O_CREAT) != 0 || ((oflag) & __O_TMPFILE) == __O_TMPFILE )
+
#ifndef F_GETLK
# ifndef __USE_FILE_OFFSET64
# define F_GETLK 5 /* Get record locking info. */
@@ -28,7 +28,7 @@ openat64 (dfd, file, oflag)
const char *file;
int oflag;
{
- assert ((oflag & O_CREAT) == 0);
+ assert (!__OPEN_NEEDS_MODE(oflag));
#ifdef __NR_openat
return INLINE_SYSCALL (openat, 3, dfd, file, oflag | O_LARGEFILE);
@@ -22,14 +22,14 @@
#include <stdio.h>
#include <sysdep-cancel.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If __OPEN_NEEDS_MODE(OFLAG),
a third argument is the file protection. */
int
__libc_open (const char *file, int oflag, ...)
{
int mode = 0;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -59,7 +59,7 @@ __open_nocancel (const char *file, int oflag, ...)
{
int mode = 0;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -22,14 +22,14 @@
#include <stdio.h>
#include <sysdep-cancel.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If __OPEN_NEEDS_MODE(OFLAG),
a third argument is the file protection. */
int
__libc_open64 (const char *file, int oflag, ...)
{
int mode = 0;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -21,14 +21,14 @@
#include <stdio.h>
#include <sysdep-cancel.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If __OPEN_NEEDS_MODE(OFLAG),
a third argument is the file protection. */
int
__libc_open64 (const char *file, int oflag, ...)
{
int mode = 0;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);
@@ -67,7 +67,7 @@ __OPENAT (fd, file, oflag)
int oflag;
{
mode_t mode = 0;
- if (oflag & O_CREAT)
+ if (__OPEN_NEEDS_MODE(oflag))
{
va_list arg;
va_start (arg, oflag);