Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: comp.lang.c Subject: Re: A better perror() (Was: Re: Accessing argc ...) Message-ID: <883@mcgill-vision.UUCP> Date: Mon, 7-Sep-87 05:44:33 EDT Article-I.D.: mcgill-v.883 Posted: Mon Sep 7 05:44:33 1987 Date-Received: Sat, 19-Sep-87 05:40:51 EDT References: <22@flmis06.ATT.COM> <28700015@ccvaxa> <853@mcgill-vision.UUCP> <1427@chinet.UUCP> Organization: McGill University, Montreal Lines: 34 In article <1427@chinet.UUCP>, rlk@chinet.UUCP (Richard Klappal) writes: > In article <1351@killer.UUCP> molly@killer.UUCP (Molly Fredericks) writes: >> In article <853@mcgill-vision.UUCP>, mouse@mcgill-vision.UUCP (der Mouse) writes: >>> In article <28700015@ccvaxa>, aglew@ccvaxa.UUCP quotes: >>>> I have always thought that perror(str) was silly - sometimes I >>>> want str to be the command name, sometimes the command plus all >>>> arguments... >>> Wish perror() were printflike, perhaps like syslog() [which] >>> accepts a printf format, except that %m means insert >>> sys_errlst[errno]. (Or close to that, at least - if errno is an unknown error, it inserts "Unknown error" (stock perror) or "Unknown error (%d)" with the number inserted (my perror).) > My solution to this is > extern int errno; > extern char *sys_errlist[]; > #define SYS_ERRMSG sys_errlist[errno] > : > printf("..whatever..: %s\n", args_for_whatever, SYS_ERRMSG); > This method assumes that 'errno' has been correctly supplied a value. > (e.i.[sic], That an error occured.) It also assumes that the value in errno is a valid index into sys_errlist! The warning in the man page is there for a reason. Wouldn't it be just wonderful to see Cannot open input file foo.in: ^ZA^DZPPPYPYXU^I^S^B^QzQYh^Y^CB^DYPYoZ#^B because whoever did the UNIX port your code happens to be compiled on neglected to add their new error codes to sys_errlist[]? der Mouse (mouse@mcgill-vision.uucp)