2003-07-31 17:04:09

by Zack Brown

[permalink] [raw]
Subject: Re: incompatible open modes

Hi John,

The best place to ask is on the linux-kernel mailing list (CCed).

Good luck,
Zack

On Thu, Jul 31, 2003 at 12:09:14PM -0400, Ata, John wrote:
> Hi Zach,
>
> I don't know if you're the right contact... just wondered how I go about
> getting information as to the intent of the Linux kernel... the manpage on
> "open" states that if a file is opened "O_RDONLY|O_TRUNC", the O_TRUNC is
> either ignored or an error is returned. The 2.4 kernel appears to
> cheerfully truncate the file on open. I wondered which behavior is
> actually intended.
>
> Thanks for your time...
>
> Take care,
> ------
> John G. Ata
> DigitalNet, LLC
> XTS-400 Software Development
> MailTo:[email protected]
> Phone:(703) 563-8092
>
> O_TRUNC
> If the file already exists and is a regular file and the
> open
> mode allows writing (i.e., is O_RDWR or O_WRONLY) it
> will be
> truncated to length 0. If the file is a FIFO or terminal
> device
> file, the O_TRUNC flag is ignored. Otherwise the
> effect of
> O_TRUNC is unspecified. (On many Linux versions it
> will be
> ignored; on other versions it will return an error.)

--
Zack Brown


2003-07-31 17:36:05

by Andries Brouwer

[permalink] [raw]
Subject: Re: incompatible open modes

> On Thu, Jul 31, 2003 at 12:09:14PM -0400, Ata, John wrote:

> > the manpage on "open" states that if a file is opened "O_RDONLY|O_TRUNC",
> > the O_TRUNC is either ignored or an error is returned. The 2.4 kernel
> > appears to cheerfully truncate the file on open. I wondered which
> > behavior is actually intended.
> >
> > O_TRUNC
> > If the file already exists and is a regular file and the open
> > mode allows writing (i.e., is O_RDWR or O_WRONLY) it will be
> > truncated to length 0.
> > Otherwise the effect of O_TRUNC is unspecified.
> > (On many Linux versions it will be ignored; on other versions
> > it will return an error.)

This was just recently discussed, and it became clear that the parenthetical
remark only led to confusion. It has been deleted. Instead

The (undefined) effect of O_RDONLY | O_TRUNC various among
implementations. On many systems the file is actually
truncated.

has been added.

Andries