Mail Archives: djgpp/2001/09/14/08:36:44
Ben Davis <ben AT vjpoole DOT freeserve DOT co DOT uk> 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.
- Raw text -