delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/06/05:20:32

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Flaw in tmpfile() ?
Date: Mon, 06 Oct 1997 09:47:29 +0200
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 37
Message-ID: <34389791.4780C29@LSTM.Ruhr-UNI-Bochum.De>
NNTP-Posting-Host: c64.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi,
I just stumbled across a little flaw in tmpfile(). It opens
the file according to the current setting of _fmode either
int text or binary mode. IMHO this should at least be mentioned
in the docs ;-)

OTOH...
Is there any reason why this cannot be silently changed
to O_BINARY? Given, I write text to a binary file, the
ending LF will not be changed to CRLF. seeking back to the
beginning of the file and re-reading it, lines will
simply be terminated with LF, since there is no CRLF mapping.
So I cannot see what use is in O_TEXT. OK, I think
there is no real harm in fwriting out a float and having
a 0xa in its exponent replaced by 0xd0a, because in reading
back the effect is undone (if fread() and fwrite() fiddle with 
that at all, I'm not sure). The only pitfall I can think
of is a program seeking random locations in the file and go
amiss because the assumed blocksize of data is not what is
really used in writing. And this can be avoided by using
O_BINARY. So, unless there is a good reason to keep things
as they are, I propose to change the mode.

-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


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