[comp.unix.questions] Error reporting

flee@gondor.psu.edu (Felix Lee) (11/15/87)

In article <4110@watdragon.waterloo.edu> jmsellens@watdragon.waterloo.edu (John M. Sellens) writes:
> If I may, I would like to propose some error message guidelines,
> which some of you undoubtedly will think of as obvious.
[various obvious things...]

int errorf(char *format, ...);
void xerrorf(int exitcode, char *format, ...);
	Report an error, using printf-like arguments.  '%m' gets expanded to
	sys_errlist[errno] (similar to BSD syslog(3)).  Umm, how about '%p'
	getting expanded to basename(argv[0])?  xerrorf() will also exit().
	So you can say
		xerrorf(42, "%p: can't open '%s': %m\n", filename);

Is there a commonly-accepted error function?  Does POSIX provide a standard
error function (other than perror)?

> - Always use exit() to set the exit status of your program.

Unix doesn't make exit status visible enough.  Unless you program in shell,
you probably don't pay much attention to exit status.  VM/CMS will show
non-zero return codes in your prompt.  In Unix, you have to say "echo
$status" or "echo $?" explicitly.  Csh at least shows exit status of
background jobs.  With ksh you could probably put $? in your prompt.

Because of high visibility, most of CMS's utilities have return codes with
well-defined meanings.  Unix programs tend not to make distinctions other
than true and false.  Notable exceptions are fsck and <sysexits.h>.
--
Felix Lee	flee@gondor.psu.edu	{cbosgd,cmcl2}!psuvax1!gondor!flee