In article <. com>
Peter Nilsson <> wrote:
>No standard library function is allowed to set errno to 0. If you
>think about this, you'll realise that this allows the caller to
>delay error detection. If the caller sets errno to zero, then rather
>than having to check errno after every function, it can delay the
>test until later, possibly culling mutliple tests in the process.
The premise here is correct (no standard library function can clear
errno), but the conclusion is not. Successful operations are
allowed to set errno to some nonzero value. Hence:
errno = 0;
do_some_work();
if (errno) ...
may misfire, thinking something went wrong when all went well. I
think this was a bad design decision (not that errno itself is
exactly wonderful

), but it is in the C standards, so we must
live with it.
As a practical matter, many (far too many) Unix-derived systems
actually do set errno to ENOTTY on the first successful I/O from
or to a (non-device) file. If you have ever had email returned
with something like:
Subject: cannot send mail to joe.typo@host: Not a typewriter
this is the reason. Someone did an "errno = 0; do_some_work();
if (errno)". In this case, the work involved looking up the
user (whose name has a typo and hence does not exist); along
the way, something did some I/O; this set errno to ENOTTY, and
strerror(ENOTTY) is "Not a typewriter". Well, of course Joe
is not a typewriter, but what has that to do with anything?

--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.