From: utzoo!decvax!ittvax!swatt
Newsgroups: net.sources
Title: Source for UNIX errmt program
Article-I.D.: ittvax.409
Posted: Tue Aug 10 11:21:34 1982
Received: Thu Aug 12 06:56:01 1982

Several people have requested this; it's quite short so I'm posting it
here (it's also amazingly cheap; "_doprnt" does all the work!).

The function names "error" and "remark" are, of course, gleaned from
Software Tools.  They work in a similar manner, appending a newline at
the end.  Thus:

	error ("Too many files (%d); max is %d", nfiles, MAXFILES);

is all you need.  The format string accepted by error and remark (and
fperror, and fpremark) is the same as for printf.  Variable number of
arguments works the same way as well.

fperror, is just like error, except that it appends the standard system
error message (like perror).  fpremark is just like remark with the
same addition.

I don't believe it depends on 4.1bsd stdio internals, but I could be
wrong.  I seem to recall moving this stuff to an ONYX but if so it was
a long time ago and I may be fooling myself.  It just occurred to me
people on system III **might** have a different formatted print
function; I've made this stuff work under IS/1 (derivative of PWB), and
there were minor differences.  If anyone has trouble, I can dig up the
differences and post them as well.

	- Alan S. Watt
======================================================================
sed 's/^	//' >error.c <
	#define NOTOK	(-1)
	
	/* VARARGS1 */
	error (mesg, args)
	char *mesg;
	{
		_doprnt (mesg, &args, stderr);
		putc ('\n', stderr);
		exit (NOTOK);
	}
	
	extern	errno;
	extern	sys_nerr;
	extern	char *sys_errlist[];
	#ifdef lint
	 int	errno;
	 int	sys_nerr;
	 char *sys_errlist[1];
	#endif lint
	static	char ehuh[]	= "Unknown System Error";
	
	/* VARARGS1 */
	fperror (mesg, args)
	char *mesg;
	{
		char *err = ((unsigned)errno >= sys_nerr ? ehuh : sys_errlist[errno]);
	
		_doprnt (mesg, &args, stderr);
		fprintf (stderr, ": %s\n", err);
		exit (NOTOK);
	}
	
	/*VARARGS1*/
	remark (mesg, args)
	char *mesg;
	{
		_doprnt (mesg, &args, stderr);
		putc ('\n',stderr);
	}
	
	/*VARARGS1*/
	fpremark (mesg, args)
	char *mesg;
	{
		char *err = ((unsigned)errno >= sys_nerr ? ehuh : sys_errlist[errno]);
	
		_doprnt (mesg, &args, stderr);
		fprintf (stderr, ":%s\n", err);
	}
!EOF
sed 's/^	//' >error.3a <