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 Subject: Re: A better perror() (Was: Re: Accessing argc ...) Message-ID: <25932@sun.uucp> Date: Tue, 18-Aug-87 16:09:49 EDT Article-I.D.: sun.25932 Posted: Tue Aug 18 16:09:49 1987 Date-Received: Fri, 21-Aug-87 02:42:00 EDT References: <22@flmis06.ATT.COM> <28700015@ccvaxa> <853@mcgill-vision.UUCP> <1351@killer.UUCP> Sender: news@sun.uucp Lines: 28 > The varargs functions and whatnot look more than adaquate for doing > something like this. What exactly is `syslog()', and how would I get > ahold of it? "syslog" is a routine that sends a message to the "syslog" daemon on 4.2BSD and 4.3BSD. It is definitely NOT a replacement for "printf", since it won't print its message to a file or stuff it into a string; the "syslog" daemon will send the message to the system console (NOT to your terminal!) or to a log file. It is intended for system log messages (hence the name). The way "syslog" implements "%m" is fairly trivial; it has an internal buffer, and it copies the format string to that buffer, replacing all occurrences of "%m" with the text of the error message corresponding to the system error code. It then uses the string in that buffer, rather than using the format string passed to it, as the format string for "sprintf" when it generates the text of the message. I tend to agree with Doug Gwyn that a version of "perror" that returns the error message for a given error code as a string is a better idea; not all error messages are generated by "perror", and you wouldn't want to have to add other "%" codes for error codes from other packages. (In general, you probably couldn't do so, even if you wanted to; what if you bought a DBMS that has its own set of error codes and routines to generate error strings from them? How would you extend "printf" to handle them? What happens if you run out of format codes?) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com