/************** * *apueerror.h * *************/#include <apue.h> #include <stdio.h> #inc
Lude <errno.h>/* for definition of errno */#include <stdarg.h>/* ISO C variable aruments * *
static void Err_doit (int, int, const char *, va_list);
* * Nonfatal error related to a system call.
* Print A and return.
*/void Err_ret (const char *FMT, ...)
{va_list ap;
Va_start (AP, FMT);
Err_doit (1, errno, FMT, AP);
Va_end (AP);
} * * Fatal error related to a system call.
* Print a message and terminate.
*/void Err_sys (const char *FMT, ...)
{va_list ap;
Va_start (AP, FMT);
Err_doit (1, errno, FMT, AP);
Va_end (AP);
Exit (1);
} * * Fatal error unrelated to a system call.
* Error code passed as explict parameter. * Print a message and terMinate.
*/void Err_exit (int error, const char *FMT, ...)
{va_list ap;
Va_start (AP, FMT);
Err_doit (1, error, FMT, AP);
Va_end (AP);
Exit (1);
} * * Fatal error related to a system call.
* Print a message, dump core, and terminate.
*/void Err_dump (const char *FMT, ...)
{va_list ap;
Va_start (AP, FMT);
Err_doit (1, errno, FMT, AP);
Va_end (AP); Abort (); /* Dump core and Terminate */exit (1);
/* shouldn ' t get here/* nonfatal error unrelated to a system call.
* Print A and return.
*/void Err_msg (const char *FMT, ...)
{va_list ap;
Va_start (AP, FMT);
Err_doit (0, 0, FMT, AP);
Va_end (AP);
} * * Fatal error unrelated to a system call.
* Print a message and terminate.
*/void Err_quit (const char *FMT, ...) {
Va_list ap;
Va_start (AP, FMT);
Err_doit (0, 0, FMT, AP);
Va_end (AP);
Exit (1);
/* Print a message and return to caller.
* Caller Specifies "Errnoflag".
*/static void Err_doit (int errnoflag, int error, const char *FMT, va_list ap) {char buf[maxline];
vsnprintf (buf, Maxline, FMT, AP);
if (Errnoflag) snprintf (Buf+strlen (BUF), Maxline-strlen (BUF), ":%s", strerror (Error));
strcat (buf, "\ n"); Fflush (stdout);
/* In case stdout and stderr are same * * fputs (buf, stderr); Fflush (NULL); /* Flushes all stdio output streams */}