This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Use mode_t in open and friends
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Rasmus Villemoes <rv at rasmusvillemoes dot dk>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 16 May 2014 22:40:41 +0200
- Subject: Re: [PATCH] Use mode_t in open and friends
- Authentication-results: sourceware.org; auth=none
- References: <87k3afhsua dot fsf at rasmusvillemoes dot dk> <87a9banc4i dot fsf at igel dot home> <20140503092848 dot GC15537 at domone dot podge> <53651EB2 dot 10100 at redhat dot com> <87ha53xn7u dot fsf at rasmusvillemoes dot dk>
On Tue, May 06, 2014 at 11:36:53AM +0200, Rasmus Villemoes wrote:
> Pedro Alves <palves@redhat.com> writes:
>
> > On 05/03/2014 10:28 AM, OndÅej BÃlka wrote:
> >> On Thu, Apr 24, 2014 at 02:30:21PM +0200, Andreas Schwab wrote:
> >>> Rasmus Villemoes <rv@rasmusvillemoes.dk> writes:
> >>>
> >>>> The sole varargs argument to open and friends has type mode_t, not int.
> >>>
> >>> Varargs use the promoted type, but mode_t traditionally has been
> >>> unsigned short.
> >>>
> >> So which solution do you prefer? Adding a custom type for that as
> >> suggested in sibling threads? What about just adding a cast like
> >>
> >> mode = (mode_t) va_arg (arg, int);
> >>
>
> That requires sizeof(mode_t) <= sizeof(int) - which (I think) is the
> case on all current and probably also all future platforms, but nothing
> guarantees it.
>
> > Might be overkill for this instance alone, but another option
> > would be letting the compiler do the work.
>
> Yes, that is definitely the best way. It would be nice if gcc exposed
> something like __builtin_promoted_type(T) so one could simply say
> va_arg(arg, __builtin_promoted_type(mode_t)); or even better if gcc had
> a switch to simply DTRT when it encounters a va_arg with a
> non-self-promoting type. gcc certainly already contains the
> infrastructure to do this.
>
Could you prepare it as v2 of this patch?