@@ -37,6 +37,10 @@ extern int __have_atfcts attribute_hidden;
#ifdef O_CLOEXEC
extern int __have_o_cloexec attribute_hidden;
#endif
+
+/* The correct type to use when retrieving a mode_t argument passed as a vararg. */
+typedef __typeof__(+(mode_t)0) promoted_mode_t;
+
#endif
#endif
@@ -30,7 +30,7 @@ __libc_open (file, oflag)
const char *file;
int oflag;
{
- int mode;
+ mode_t mode;
if (file == NULL)
{
@@ -41,9 +41,9 @@ __libc_open (file, oflag)
if (oflag & O_CREAT)
{
va_list arg;
- va_start(arg, oflag);
- mode = va_arg(arg, int);
- va_end(arg);
+ va_start (arg, oflag);
+ mode = va_arg (arg, promoted_mode_t);
+ va_end (arg);
}
__set_errno (ENOSYS);
@@ -28,7 +28,7 @@ __libc_open64 (file, oflag)
const char *file;
int oflag;
{
- int mode;
+ mode_t mode;
if (file == NULL)
{
@@ -40,7 +40,7 @@ __libc_open64 (file, oflag)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -38,7 +38,7 @@ __openat (fd, file, oflag)
const char *file;
int oflag;
{
- int mode;
+ mode_t mode;
if (file == NULL)
{
@@ -64,7 +64,7 @@ __openat (fd, file, oflag)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -31,7 +31,7 @@ __openat64 (fd, file, oflag)
const char *file;
int oflag;
{
- int mode;
+ mode_t mode;
if (file == NULL)
{
@@ -57,7 +57,7 @@ __openat64 (fd, file, oflag)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -291,7 +291,7 @@ sem_open (const char *name, int oflag, ...)
try_create:
va_start (ap, oflag);
- mode = va_arg (ap, mode_t);
+ mode = va_arg (ap, promoted_mode_t);
value = va_arg (ap, unsigned int);
va_end (ap);
@@ -34,7 +34,7 @@ __libc_open (const char *file, int oflag, ...)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, mode_t);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
else
@@ -41,7 +41,7 @@ __openat (fd, file, oflag)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, mode_t);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
else
@@ -24,13 +24,13 @@
int
__libc_open64 (const char *file, int oflag, ...)
{
- int mode = 0;
+ mode_t mode = 0;
if (oflag & O_CREAT)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -27,13 +27,13 @@
int
__libc_open (const char *file, int oflag, ...)
{
- int mode = 0;
+ mode_t mode = 0;
if (oflag & O_CREAT)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -57,13 +57,13 @@ weak_alias (__libc_open, open)
int
__open_nocancel (const char *file, int oflag, ...)
{
- int mode = 0;
+ mode_t mode = 0;
if (oflag & O_CREAT)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -27,13 +27,13 @@
int
__libc_open64 (const char *file, int oflag, ...)
{
- int mode = 0;
+ mode_t mode = 0;
if (oflag & O_CREAT)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -47,7 +47,7 @@ __mq_open (const char *name, int oflag, ...)
va_list ap;
va_start (ap, oflag);
- mode = va_arg (ap, mode_t);
+ mode = va_arg (ap, promoted_mode_t);
attr = va_arg (ap, struct mq_attr *);
va_end (ap);
}
@@ -26,13 +26,13 @@
int
__libc_open64 (const char *file, int oflag, ...)
{
- int mode = 0;
+ mode_t mode = 0;
if (oflag & O_CREAT)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, int);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
@@ -71,7 +71,7 @@ __OPENAT (fd, file, oflag)
{
va_list arg;
va_start (arg, oflag);
- mode = va_arg (arg, mode_t);
+ mode = va_arg (arg, promoted_mode_t);
va_end (arg);
}
On some platforms, mode_t is narrower than int and hence promoted to int when passed through as the optional argument to an open-like function; on others, mode_t is at least as wide as int and hence passed through as-is. To accomodate the case where mode_t might be strictly wider than int (making va_arg(ap, int) wrong to use), use whatever type mode_t promotes to as the second argument to va_arg. Rich Felker suggested that this could be obtained simply as __typeof__(+(mode_t)0) (which works since POSIX insists that mode_t is an integral type). Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk> --- include/fcntl.h | 4 ++++ io/open.c | 8 ++++---- io/open64.c | 4 ++-- io/openat.c | 4 ++-- io/openat64.c | 4 ++-- nptl/sem_open.c | 2 +- sysdeps/mach/hurd/open.c | 2 +- sysdeps/mach/hurd/openat.c | 2 +- sysdeps/posix/open64.c | 4 ++-- sysdeps/unix/sysv/linux/generic/open.c | 8 ++++---- sysdeps/unix/sysv/linux/generic/open64.c | 4 ++-- sysdeps/unix/sysv/linux/mq_open.c | 2 +- sysdeps/unix/sysv/linux/open64.c | 4 ++-- sysdeps/unix/sysv/linux/openat.c | 2 +- 14 files changed, 29 insertions(+), 25 deletions(-)