From patchwork Mon May 19 22:21:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 350432 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 534A414007E for ; Tue, 20 May 2014 08:22:44 +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=X54C4XaIUp4lkzIqzbxqmnV7WavrdeI 7eqohb7Ihulwc6/Fl84sQ+VXRNEb4QhdSXhv/PvApMYNnPM0+dbd7Bp5IU4Ad+oq B9i38DNpUndwOcl15DoTtoL263WTqQ1CShNgnULf3EFqn6naltsf677ktzuhTATe tPownuhjjU/Y= 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=NUgs0ZBqdDlXw2OKcyU65JUk5NI=; b=xG255 KoZ35+XAMtBXbGoBgFA4LHo4ujiuSU5FQ9SMDhAT6jE5sKjiKSrfGvngRLgM27EY /bNSnzDLsudHSmbqd8w+6YwjnByPCV2UjXrCkfwQ9dpktf7wxyipdCZ/a4yJTXwM J7B7BSrAvMcpEv8F8+8CY6tDTwVnP0HHZQPTPw= Received: (qmail 1853 invoked by alias); 19 May 2014 22:22:38 -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 1835 invoked by uid 89); 19 May 2014 22:22:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mail-lb0-f180.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=MGDAuEzfPmAF2ZMhqy225kzu9ah4pyWRyMz4H8pLwYg=; b=FbWgdlCCsksJ+r27kuayJBBBVzt9mRq5BKmogNTgAPuav+WwkSl4YAsdwXwPq9FBpa hIsWEhOBT7+BWqUxUy07DaUuwpaSfHOz8Nsjr5OjXITVlzkpmYg7E/d8OuNp9qhhI4bV fdsBnu4GxZLBJ+iZHt8WtmAT4150v92fsx3N9ku0yjBfhcBCiq99fIM6B1hlMGAcqAR5 3AIWdGlERfTrBJmXJeGA6cau38TjXJ8zTpfz4gOpVpyMv9Ct2UBsppIiOQatAQg4/8G+ RCwfVOEmagiJJrPelJ3NR7awWWSkChoYnTUTqY+lud1iCdeVQqIhwqvc7TtcPdp21kld bF1w== X-Gm-Message-State: ALoCoQlFoAIEYDZO+AGSr40VXjN92QvU/P2C+roHOFOS4qR/NVVkriG4n0QK5WWTVtwYqvj0HM5K X-Received: by 10.152.36.134 with SMTP id q6mr28923499laj.29.1400538151362; Mon, 19 May 2014 15:22:31 -0700 (PDT) From: Rasmus Villemoes To: libc-alpha@sourceware.org Cc: neleai@seznam.cz, Rasmus Villemoes Subject: [PATCH v2] Handle possible vararg promotion of mode_t in open and friends Date: Tue, 20 May 2014 00:21:50 +0200 Message-Id: <1400538110-7066-1-git-send-email-rv@rasmusvillemoes.dk> In-Reply-To: <20140516204041.GB17252@domone.podge> References: <20140516204041.GB17252@domone.podge> 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). --- 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 +- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/io/open.c b/io/open.c index 24aa380..c40a6b7 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 (ap, __typeof__(+(mode_t)0)); + va_end (arg); } __set_errno (ENOSYS); diff --git a/io/open64.c b/io/open64.c index 3f3d2e8..1e3750d 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } diff --git a/io/openat.c b/io/openat.c index 2d82270..c4cdf6c 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } diff --git a/io/openat64.c b/io/openat64.c index c0c4e19..be69e5f 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } diff --git a/nptl/sem_open.c b/nptl/sem_open.c index cf91859..e729acd 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, __typeof__(+(mode_t)0)); 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..e99e685 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } else diff --git a/sysdeps/mach/hurd/openat.c b/sysdeps/mach/hurd/openat.c index 318cb22..438d650 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } else diff --git a/sysdeps/posix/open64.c b/sysdeps/posix/open64.c index 64d192a..6615400 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } diff --git a/sysdeps/unix/sysv/linux/generic/open.c b/sysdeps/unix/sysv/linux/generic/open.c index 4f73fa0..7098f11 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 (ap, __typeof__(+(mode_t)0)); 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } diff --git a/sysdeps/unix/sysv/linux/generic/open64.c b/sysdeps/unix/sysv/linux/generic/open64.c index 93d79e3..ed26c8f 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } diff --git a/sysdeps/unix/sysv/linux/mq_open.c b/sysdeps/unix/sysv/linux/mq_open.c index 38194ac..0fb38a6 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, __typeof__(+(mode_t)0)); 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..648fef7 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 (ap, __typeof__(+(mode_t)0)); va_end (arg); } diff --git a/sysdeps/unix/sysv/linux/openat.c b/sysdeps/unix/sysv/linux/openat.c index 2cf233b..d0f06c9 100644 --- a/sysdeps/unix/sysv/linux/openat.c +++ b/sysdeps/unix/sysv/linux/openat.c @@ -161,7 +161,7 @@ __OPENAT (fd, file, oflag) { va_list arg; va_start (arg, oflag); - mode = va_arg (arg, mode_t); + mode = va_arg (ap, __typeof__(+(mode_t)0)); va_end (arg); }