delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2013/07/20/10:15:21

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
From: "Stephen J. Turnbull" <turnbull AT sk DOT tsukuba DOT ac DOT jp>
To: djgpp-workers AT delorie DOT com
Subject: Re: Set _IOERR if the file stream has been opened in wrong mode.
In-Reply-To: <83wqolxy5m.fsf@gnu.org>
References: <51E5D0C6 DOT 1060404 AT gmx DOT de>
<83y5951a79 DOT fsf AT gnu DOT org>
<51E702E0 DOT 3010809 AT gmx DOT de>
<83fvvc1t0x DOT fsf AT gnu DOT org>
<8738rcsdik DOT fsf AT uwakimon DOT sk DOT tsukuba DOT ac DOT jp>
<201307180459 DOT r6I4xWxV010383 AT envy DOT delorie DOT com>
<51E9D758 DOT 8000209 AT gmx DOT de>
<CAA-ihx_SR7sb9+Tq_Ok+VM9FbjPLp9Lvk8a+bXf94oj13MTeWg AT mail DOT gmail DOT com>
<87fvv9r6ba DOT fsf AT uwakimon DOT sk DOT tsukuba DOT ac DOT jp>
<8361w5zl86 DOT fsf AT gnu DOT org>
<87a9lhqz60 DOT fsf AT uwakimon DOT sk DOT tsukuba DOT ac DOT jp>
<83wqolxy5m DOT fsf AT gnu DOT org>
X-Mailer: VM undefined under 21.5 (beta32) "habanero" b0d40183ac79 XEmacs
Lucid (x86_64-unknown-linux)
Date: Sat, 20 Jul 2013 23:15:01 +0900
Message-ID: <878v11qpwa.fsf@uwakimon.sk.tsukuba.ac.jp>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Eli Zaretskii writes:

 > > From: "Stephen J. Turnbull" <turnbull AT sk DOT tsukuba DOT ac DOT jp>
 > > Date: Sat, 20 Jul 2013 19:54:47 +0900
 > > 
 > > Eli Zaretskii writes:
 > >  > > From: "Stephen J. Turnbull" <turnbull AT sk DOT tsukuba DOT ac DOT jp>
 > >  > > Date: Sat, 20 Jul 2013 17:20:25 +0900
 > >  > > 
 > >  > > I would assume that
 > >  > > 
 > >  > >     ifp = fopen(infile, "r"); ofp = fopen(outfile, "w");
 > >  > > 
 > >  > > produces an unwritable and an unreadable file respectively
 > >  > 
 > >  > There's no such thing as "unreadable file" on DOS.
 > > 
 > > Sorry, I didn't mean "file" (too much Python programming, obviously),
 > > I meant "FILE*".  Can you read from ofp on DOS?
 > 
 > That last question is no longer in DOS-land, it is in the libc-land.
 > Because DOS knows nothing of 'FILE *'.

*sigh* Try "Can you read from a (FILE*|file descriptor) opened in mode
'w' in a DJGPP program?" instead, which is what I intended.  (My
original question was "what semantics should this C code have?" and
above is my answer, imprecisely stated.)  Or you could ask the same
question for a set of relevant DOS implementations.

 > So we are back at square one: is there any good reason, apart of
 > "other libraries do that", which mandates that a FILE stream open
 > with "w" be unreadable?

If you can write to ifp and read from ofp as above, why is there a
mode argument to the open functions at all?  In fact the man pages for
open(2) on both Linux and BSD specify the that O_RDONLY and O_WRONLY
flags mean open in "read-only" and "write-only" modes respectively.

I would assume that the designers wanted to avoid situations where
FILE* or fd is passed around and somebody gets confused and overwrites
a file that was supposed to be readonly.

I really think the lack of a specification here is due simply to the
fact that nobody considered that anything else would be reasonable,
and it's just an embarrassing oversight (for the standards committees).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019