bug-hurd
[Top][All Lists]
Advanced

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

Weird O_RDWR flag definition


From: Adam Tkac
Subject: Weird O_RDWR flag definition
Date: Fri, 31 Oct 2008 23:56:27 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

Hi all,

I've found weird issue with O_RDWR access flag. When you want check
if file is opened for read-only or read-write access you can write
code like:

if (mode & O_WRONLY)
        die();

That piece of code should fail only if file is opened with write-only
access mode.

Main problem is that GNU/Hurd has this O_RDWR flag definition:

#define O_RDWR (O_RDONLY|O_WRONLY)

It looks like bad for me because code written above fails even if file
is opened with read-write access.

Yes, you could use condition like

if (!((mode & O_RDWR) || (mode & O_RDONLY)))
        die();

but it is really not intuitive and will mysteriously break many
programs.

I think O_RDWR definition should be revised, isn't it? That definition
is part of libc but change will affect whole OS.

Regards, Adam

-- 
Adam Tkac




reply via email to

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