#include "header.h" void err_normal(const char *fmt, ...) { va_list args; va_start(args, fmt); /* initialize */ __process_error(fmt, args); /* process this error */ va_end(args); } void err_fatal(const char *fmt, ...) { va_list args; va_start(args, fmt); /* initialize */ __process_error(fmt, args); /* process this error */ va_end(args); exit(1); /* exit gracefully */ } void __process_error(const char *fmt, va_list args) { int error; /* * Save errno, to make sure we can restore it if one of the following * function calls changes it for some reason. */ error = errno; /* * Print: 1. caller's error message, * 2. system error message if applicable, * 3. add newline charater. */ vfprintf(stderr, fmt, args); if (error != 0) { /* a system error has occurred */ fprintf(stderr, ": %s", strerror(error)); putc('\n', stderr); } }