'exit(1);' considered useless; perror; stdio; etc.

chris at umcp-cs.UUCP chris at umcp-cs.UUCP
Mon Feb 6 16:05:23 AEST 1984


Speaking of "perror"... one thing I'd like to see is a ``%'' format
for printf that interprets an error number, so that I could say
(for example)

#include <stdio.h>

/*
 * Log an error message, and print it to stderr too.  'err' is a Unix(tm)
 * system error number (one of the beasts from <errno.h>).
 */
LogError (err) int err; {
    static FILE *logfile;

    /* Replace '#' with appropriate char.  Can't use 'E', sigh. */
    fprintf (stderr, "%#\n", err);
    if (logfile || (logfile = fopen ("/foo/bar/errors", "a")))
	fprintf (logfile, "%#\n", err);
}

Many times I've wanted to print the error message associated with
"errno" -- but not the way perror(3) prints it.  I've had to fall
back on "extern char *sys_errlist[]; extern int sys_nerr;" hacks.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris.umcp-cs at CSNet-Relay



More information about the Comp.unix mailing list