From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Possible bug in libc tmpnam() function Date: 14 Sep 2001 11:19:56 GMT Organization: Aachen University of Technology (RWTH) Lines: 29 Message-ID: <9nsp4s$qe$1@nets3.rz.RWTH-Aachen.DE> References: <9nsm2c$q0f$1 AT news5 DOT svr DOT pol DOT co DOT uk> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 1000466396 846 137.226.32.75 (14 Sep 2001 11:19:56 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 14 Sep 2001 11:19:56 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Ben Davis wrote: > Hi, > I wrote a program which reads a large quantity of data from one file and > then writes data to another. The output file is chosen using the tmpnam() > function, to be renamed at the end. It is most convenient for me to detect > errors by checking if errno is nonzero once at the end of the program. It may seem like it's convenient, but it just doesn't work. You should look into errno if and _only_ if some function signalled an error by returning an appropriate value. There's no promise whatsoever that errno is going to be preserved across successful libc function calls. To quote the ANSI C9x draft Standard: [#3] The value of errno is zero at program startup, but is never set to zero by any library function.159) The value of errno may be set to nonzero by a library function call whether or not there is an error, provided the use of errno is not documented in the description of the function in this International Standard. Note that tmpnam() is not documented to use errno, so the "whether or not there is an error" part applies, here. Thus, the bug is in your program, not in DJGPP. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.