From patchwork Sun Aug 3 14:53:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 376063 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7EC3B1400A3 for ; Mon, 4 Aug 2014 00:55:48 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=ffVS3UoIbmPo3FYhiiXo0fegWKU6B/u G1bR+bKXF+XjYGyJ+9nL1/uoNdu5vpvgblkv9JAlWjMzVzyQaFYfglFO8uATAE8X Mor4ko58ZC41OK872gnHKydrOaIvCekn1D71Ztpv7ZHOmON6FnBlvBiXs2yDH89e wWAvk9OvYPng= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=V3sXG9osNS4TY4Z3Zx+Eubw2VZU=; b=DPQJz pODMYBQtXS3ILt20M4CKyl+G86JvtdcmsNHIucDfBqJnVVuT9u2YcKrD7bbH/4SE qZ4TygX2s8MkKj+cs3VSOGSvsTObNvKyLVkM4n50I/vUdGpVvddjjD3ifl1K4t5s 3w0FbPfiS9mcmJCNhdDm2oLZ2G3wZcU+VFRgzs= Received: (qmail 5933 invoked by alias); 3 Aug 2014 14:55:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 5922 invoked by uid 89); 3 Aug 2014 14:55:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mail-lb0-f169.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Sdiq5lr1lbLzbiCR9+/YsfX7/80Xvm0RFSu9qDjFg88=; b=lU3F71EazNDaqJVMDfa8dSlZMCWFiNt+HpVZq9M4X1lAgyQfwYliKWh2Wm5rIRXnsg qUum1DuHzycU3OE58n1bYFlCUNnVBtQbOhx+89OrVmsIvSU27FCHEdzY3bFQiCZKtScH XJvnPCN1BvTMUtdNPR/SfHbf4F/TVROBQ/2RbmA6uIqUgax5p9ibks3Hl4FJr7/jJBcR ir3QH/j+q1FRbxJyA6UbKgpz7fK2sHF+3nns6j+upXqjnXXwsTATJwYEAYf6mwlU7HwQ ZiUauyzIgsbJzQv9Sf6SkUQYA5k/P5JiG9LiISBbmZSaNl1CjcInu7oZMfIXXyiIZGMw ZZcA== X-Gm-Message-State: ALoCoQkw2SqVqjN9sx+DO5nqJedxzsTXV8J/zM7rlLTfUn5Jaom7UVNxjsrBC8+nbFDN37T65uYg X-Received: by 10.112.150.106 with SMTP id uh10mr16894324lbb.11.1407077735382; Sun, 03 Aug 2014 07:55:35 -0700 (PDT) From: Rasmus Villemoes To: Mike Frysinger , libc-alpha@sourceware.org Cc: neleai@seznam.cz, Rasmus Villemoes Subject: [PATCH v3] Handle possible vararg promotion of mode_t in open and friends Date: Sun, 3 Aug 2014 16:53:55 +0200 Message-Id: <1407077635-9855-1-git-send-email-rv@rasmusvillemoes.dk> In-Reply-To: <9092367.5eHRuGpIF4@vapier> References: <9092367.5eHRuGpIF4@vapier> 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 --- 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(-) diff --git a/include/fcntl.h b/include/fcntl.h index a636f38..a9c72f7 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -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 diff --git a/io/open.c b/io/open.c index 24aa380..2d85443 100644 --- a/io/open.c +++ b/io/open.c @@ -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); diff --git a/io/open64.c b/io/open64.c index 3f3d2e8..15bada6 100644 --- a/io/open64.c +++ b/io/open64.c @@ -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); } diff --git a/io/openat.c b/io/openat.c index 2d82270..ace651c 100644 --- a/io/openat.c +++ b/io/openat.c @@ -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); } diff --git a/io/openat64.c b/io/openat64.c index c0c4e19..614fe42 100644 --- a/io/openat64.c +++ b/io/openat64.c @@ -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); } diff --git a/nptl/sem_open.c b/nptl/sem_open.c index cf91859..ded29b3 100644 --- a/nptl/sem_open.c +++ b/nptl/sem_open.c @@ -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); diff --git a/sysdeps/mach/hurd/open.c b/sysdeps/mach/hurd/open.c index 7d9b2de..640a3e4 100644 --- a/sysdeps/mach/hurd/open.c +++ b/sysdeps/mach/hurd/open.c @@ -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 diff --git a/sysdeps/mach/hurd/openat.c b/sysdeps/mach/hurd/openat.c index 318cb22..52964b0 100644 --- a/sysdeps/mach/hurd/openat.c +++ b/sysdeps/mach/hurd/openat.c @@ -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 diff --git a/sysdeps/posix/open64.c b/sysdeps/posix/open64.c index 64d192a..b43cb27 100644 --- a/sysdeps/posix/open64.c +++ b/sysdeps/posix/open64.c @@ -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); } diff --git a/sysdeps/unix/sysv/linux/generic/open.c b/sysdeps/unix/sysv/linux/generic/open.c index 4f73fa0..a1c616f 100644 --- a/sysdeps/unix/sysv/linux/generic/open.c +++ b/sysdeps/unix/sysv/linux/generic/open.c @@ -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); } diff --git a/sysdeps/unix/sysv/linux/generic/open64.c b/sysdeps/unix/sysv/linux/generic/open64.c index 93d79e3..c707db8 100644 --- a/sysdeps/unix/sysv/linux/generic/open64.c +++ b/sysdeps/unix/sysv/linux/generic/open64.c @@ -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); } diff --git a/sysdeps/unix/sysv/linux/mq_open.c b/sysdeps/unix/sysv/linux/mq_open.c index 38194ac..4fa5632 100644 --- a/sysdeps/unix/sysv/linux/mq_open.c +++ b/sysdeps/unix/sysv/linux/mq_open.c @@ -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); } diff --git a/sysdeps/unix/sysv/linux/open64.c b/sysdeps/unix/sysv/linux/open64.c index 0d63806..ac3e72a 100644 --- a/sysdeps/unix/sysv/linux/open64.c +++ b/sysdeps/unix/sysv/linux/open64.c @@ -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); } diff --git a/sysdeps/unix/sysv/linux/openat.c b/sysdeps/unix/sysv/linux/openat.c index 36555b9..f9dcda6 100644 --- a/sysdeps/unix/sysv/linux/openat.c +++ b/sysdeps/unix/sysv/linux/openat.c @@ -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); }