bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: openat wrapper assumes that O_RDONLY is disjoint from R_RDWR


From: Dan Gohman
Subject: Re: openat wrapper assumes that O_RDONLY is disjoint from R_RDWR
Date: Wed, 4 Mar 2020 09:24:33 -0800



On Tue, Mar 3, 2020 at 6:47 PM Bruno Haible <address@hidden> wrote:
Dan Gohman wrote:
> > if (flags & (O_CREAT | O_WRONLY | O_RDWR))
>
> However, this can erroneously return true on systems where O_RDWR shares
> bits with R_RDONLY.

Would
   if (flags & ((O_CREAT | O_WRONLY | O_RDWR) & ~O_RDONLY))
be correct?

That would fix the problem for systems that define O_RDONLY as Hurd does, while not breaking any known systems.

It wouldn't be correct on a hypothetical system which defines the constants like this:

#define O_WRONLY 0
#define O_RDONLY 1
#define O_RDWR 2

though I don't know of any platforms which do this.

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]