ERRNO - error indicator variable.

(ANSI Standard)

Usage:

extern int errno;

Description:

"errno" is a library variable used in error reporting. Library routines that encounter an error usually return some kind of result value that indicates an error. If the error can come from several different sources, the library routine that found the error may assign a value to "errno" to indicate the kind of error that occurred. User programs may check the value of "errno" to find out what happened.

In GCOS8 NS mode, "errno" values have no particular relationship to error codes that might be used by system software. Furthermore, the "errno" value corresponding to a particular type of error may change from one release of the compiler to the next.

Notes:

The "errno" concept has some flaws. First, many library routines do not use it. Second, "errno" values often have different meanings in different contexts. This is particularly a problem when library routine A calls library routine B. If B sets "errno", returns to A and A returns to the caller, the caller will interpret the "errno" value in the context of A and that may not be what B meant at all.

None of the library routines ever set "errno" to zero (indicating no error). This also causes confusion. For example, suppose your program calls a routine that sets "errno" but you do not check the "errno" value. Later on, you call another routine which works perfectly, but afterwards you check the "errno" value and find it is non-zero. Your program will believe that the error came from the good routine, even though it actually occurred much earlier.

All of this demonstrates that the "errno" concept is less than reliable. However, it is the error reporting scheme used by UNIX, and compatibility demands that it be supported. Be very careful when using it. In particular, if you are going to check it after calling a function to see if an error has occurred, explicitly set it to zero before calling the function...or test it to see if it is non-zero before the call and decide whether execution is worth continuing at all if some unknown error has taken place undetected.

See Also:

expl nsc lib perror

expl nsc lib strerror

Copyright © 1996, Thinkage Ltd.