Errno

Brandon Allbery bsa at ncoast.UUCP
Wed Jul 31 01:11:18 AEST 1985


Expires:

Quoted from <1730 at reed.UUCP> ["Re: Bug in isatty (all systems!)"], by alexis at reed.UUCP (Alexis Dimitriadis)...
+---------------
| > My 4.2bsd manual describes this in the INTRO(2) section, right before the
| > list of errno values.  Just where would you prefer that it be mentioned?
| > RTFM!
| 
|   MY 4.2bsd manual says:
| 
|       ... An
|      error number is also made available in the external variable
|      _errno_, which is not cleared on successful calls.  Thus _errno_
-----------------------------------------------------------^^^^^^^^^^^^
|      should be tested only after an error has occurred.
-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| 
|   What does "not cleared on successful calls" mean to you?  To me, it
| means that if I set errno = 0 in the beginning of my program, it will
| stay zero until a system call _fails_, then it will stay non-zero long
| enough for me to do something about it.  Now if a perfectly successful
| operation sets errno and does not bother to clear it, how can I depend
| on errno as an indication that something went _wrong_?
+---------------

Look at the underscored part of the manual fragment for that answer.

Please note that it was from intro(2), where the (2) means system calls.
System calls do NOT change errno unless there is an error.  This is so
that USER FUNCTIONS can do things with errno without having to explicitly
zero errno when they are complete in order to work similarly to system
calls.

ALL functions should have some way of indicating an error OTHER THAN errno.
Stdio has ferror(), other functions use out-of-band values like NULL or -1.
Functions provided with Unix follow this; so should your functions.

--bsa
-- 
Brandon Allbery, Unix Consultant -- 6504 Chestnut Road, Independence, OH 44131
decvax!cwruecmp!ncoast!bsa; ncoast!bsa at case.csnet; +1 216 524 1416; 74106,1032
========================> Trekkies have Warped minds. <=======================



More information about the Comp.unix.wizards mailing list