Mail Archives: djgpp-workers/2002/04/05/08:00:44
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 -