%r, and why it disappeared (a theory)

Eric Kiebler eric at washu.UUCP
Mon Oct 17 13:26:05 AEST 1983


BEWARE the _doprnt code, my son!
  The bits that twitch; the types that clash!
Use the portable varargs stuff,
  Avoid the _doprnt's teeth that gnash!

As Mark Horton pointed out, the _doprnt() routine is *not* portable
and should not be used for that reason.  Yes, of course, the code
will *never* leave your machine, but...

Just for you "my code stays at home and watches TV" folks out there,
here is a little collection of error functions which I used in code
that wasn't supposed to leave my machine either...

/*
   Error Handling Functions 
   Wash. U. Computer Systems Lab	E. Kiebler	Sept, 1982 
   Distribution allowed if and only if this entire comment is included 
*/

#include <stdio.h>
#include <sys/types.h>
#include <time.h>

extern char *ProgramName;
extern int  DebugFlag;
extern FILE *stdlog;

warning(fmt,args)
char *fmt;
{

  fprintf(stderr,"%s: (warning) ",ProgramName);
  _doprnt(fmt, &args, stderr);		/* magic */
  return(ferror(stderr)? EOF : 0);

}

error(fmt,args)
char *fmt;
{

  fprintf(stderr,"%s: (error) ",ProgramName);
  _doprnt(fmt, &args, stderr);		/* voodoo */
  return(ferror(stderr)? EOF : 0);

}

fatal(fmt,args)
char *fmt;
{

  fprintf(stderr,"%s: (fatal) ",ProgramName);
  _doprnt(fmt, &args, stderr);		/* read the manuals */
  exit(0);

}

debug(fmt,args)
char *fmt;
{

  if(DebugFlag){
    fprintf(stderr,"%s: (debug) ",ProgramName);
    _doprnt(fmt, &args, stderr);		/* wonderful! */
    fprintf(stderr,"\n");
   }

}

log(fmt,args)
char *fmt;
{
  struct tm *tp;
  extern struct tm *localtime();
  time_t clock;
  
  time(&clock);
  tp = localtime(&clock);
  fprintf(stdlog, "(%d/%d-%d:%d) ", tp->tm_mon + 1,
  	tp->tm_mday, tp->tm_hour, tp->tm_min);
  _doprnt(fmt,&args,stdlog);
  fprintf(stdlog,"\n");
}

This code was written by myself and, as far as I know, does not use
any proprietary (sp?) code (unless telling people that _doprnt()
exists is proprietary, in which case eat the code and call your lawyer).

		C A V E A T    E M P T O R
		==========================

-- 
eric
..!ihnp4!washu!eric



More information about the Comp.lang.c mailing list