delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/04/05/08:00:44

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f
Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <3CAD9FB1.4DEC7F58@phekda.freeserve.co.uk>
Date: Fri, 05 Apr 2002 13:59:29 +0100
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.19 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: redirection problem with perl
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1020128134413 DOT 26430D-100000 AT is> <3CAB1FDB DOT 68F9CF2F AT phekda DOT freeserve DOT co DOT uk> <7704-Fri05Apr2002112312+0300-eliz AT is DOT elta DOT co DOT il> <3CAD6FE7 DOT 1384C841 AT phekda DOT freeserve DOT co DOT uk> <8582-Fri05Apr2002142726+0300-eliz AT is DOT elta DOT co DOT il>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Eli Zaretskii wrote:
[snip]
> I guess that's because you can't create a file without asking to
> write to it.

That makes sense, but I have no idea if it's true. I'll write a test program
later.

> Should we reopen it with the correct open mode once it's created?

mkstemp uses _creatnew. Making _creatnew reopen the file would introduce a
race condition in mkstemp, because someone could sneak in between the close
and reopen and perhaps open the file with exclusive access. This race
condition defeats the point of having mkstemp in the first place.

But mkstemp should return a file descriptor that can be used for reading and
writing. So perhaps _creatnew should only close and reopen the file, when it
needs to change mode to open the file after creating it? I.e.:

    O_WRONLY -> just open it
    O_RDONLY -> open it, close it, re-open it read-only
    O_RDWR   -> just open it

(Obviously this is based on needing to open for writing, to create the file.)

Bye, Rich =]

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

- Raw text -


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