Reporting errors from local libraries

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jun 17 07:06:43 AEST 1989


In article <25447 at agate.BERKELEY.EDU> bks at ALFA.berkeley.edu ( Brad Sherman ) writes:
>Where is the actual space for "errno" allocated?

The usual implementation is for the C library to contain a module that
defines storage for it, for example what you get when you compile:

	/* errno.c -- C library source for the "errno" data module */
	int errno;

(Actually, the module usually also contains an secret run-time support
function that is used to log an error into errno and return a -1 value
from the failed system call.)

>If one has N libraries and all functions in these libraries return
>0 on success and -1 on failure, and one wishes, say, to set an (extern)
>integer "Localerrno" to provide additional info on failure, what is the
>guruish way to proceed?

The "errno" approach is a mistake, and I strongly recommend not returning
values via external global variables.  Use a better function interface,
for example return 0 on success and non-zero error code on failure.



More information about the Comp.lang.c mailing list