Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!texsun!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: A better perror() (Was: Re: Accessing argc ...) Message-ID: <26255@sun.uucp> Date: Fri, 21-Aug-87 15:43:09 EDT Article-I.D.: sun.26255 Posted: Fri Aug 21 15:43:09 1987 Date-Received: Sun, 23-Aug-87 06:04:30 EDT References: <22@flmis06.ATT.COM> <28700015@ccvaxa> <853@mcgill-vision.UUCP> <1427@chinet.UUCP> Sender: news@sun.uucp Followup-To: comp.unix.questions Lines: 32 Xref: mnetor comp.lang.c:3809 comp.unix.questions:3681 (This has ceased to be a discussion of C, and has become a discussion of features of UNIX. It is being redirected to comp.unix.questions.) > extern int errno; > extern char *sys_errlist[]; > > Do an 'nm' command on libc.a to confirm the existence of these names, > if not using a standard UN*X (works on SYSV, and on my BSD-derived > system.) Or, instead of outsmarting yourself by using a technique too clever by half, just look in the Effing Manual! You'll find "sys_errlist" listed in the "perror" manual page somewhere in some subsection of section 3, and "errno" described in the "intro" manual page in section 2, unless your vendor has totally screwed up their documentation. If it doesn't have "errno", it's not only not "standard UN*X", it's not any sort of UN*X; the number of programs that would be broken by omitting "errno" is very large. If it doesn't have "sys_errlist", fewer programs will be broken, but some will be. BTW, do NOT assume that the value in "errno" is a valid index into the "sys_errlist" array! The chances are good that it is, but it is NOT certain; check the "errno" value against "sys_nerr" (described along with "sys_errlist" in the manual) and make sure it's greater than zero. If it's not a valid index, generate the message some other way, preferably including the value of "errno" in decimal. (If it IS a valid index, NEVER print the value of "errno" in decimal; programs like "cpio" have a tendency to print the error number and NOT print the message, which is incredibly idiotic.) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com