the mode argument is only required to be present when the O_CREAT or
O_TMPFILE flag is used.
int openat(int fd, const char *filename, int flags, ...)
{
mode_t mode;
- va_list ap;
- va_start(ap, flags);
- mode = va_arg(ap, mode_t);
- va_end(ap);
+
+ if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, mode_t);
+ va_end(ap);
+ }
+
return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
}