lkml.org 
[lkml]   [2003]   [Jul]   [12]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Bug in open() function (?)
From Valdis.Kletnieks@vt ...
DateSat, 12 Jul 2003 01:11:12 -0400
On Fri, 11 Jul 2003 20:38:09 PDT, Andrew Morton said:
> "J.C. Wren" <jcwren@jcwren.com> wrote:
> >> > I was playing around today and found that if an existing file is opened wit
h 
> >  O_TRUNC | O_RDONLY, the existing file is truncated.> > Well that's fairly idiotic, isn't it?

Not idiotic at all, and even if it was, it's still contrary to specific
language in the manpage.

I could *easily* see some program having a line of code:

	if (do_ro_testing) openflags |= O_RDONLY;
I'd not be surprised if J.C. was playing around because a file unexpectedly
shrank to zero size because of code like this.  There's a LOT of programs that
implement some sort of "don't really do it" option, from "/bin/bash -n" to
"cdrecord -dummy".  So you do something like the above to make your
file R/O - and O_TRUNC *STILL* zaps the file, in *direct violation* of
the language in the manpage.

Whoops.  Ouch. Where's the backup tapes?

> The Open Group go on to say "The result of using O_TRUNC with O_RDONLY is
> undefined" which is also rather silly.
> 
> I'd be inclined to leave it as-is, really.

I hate to think how many programmers are relying on the *documented* behavior to
prevent data loss during debugging/test runs....
/Valdis
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 13:46    [from the cache]
©2003-2008