You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
echoping/SRC/error.c

117 lines
2.3 KiB
C

24 years ago
#include "echoping.h"
24 years ago
/* $Id$ */
24 years ago
/* Most of error-handling routines stolen from Stevens' books */
void
my_perror()
24 years ago
{
fprintf(stderr, " %s\n", sys_err_str());
24 years ago
}
/*
* Recoverable error. Print a message, and return to caller.
*
* err_ret(str, arg1, arg2, ...)
*
* The string "str" must specify the conversion specification for any args.
*/
/* VARARGS1 */
void
err_ret(char *str, ...)
24 years ago
{
va_list args;
24 years ago
va_start(args, str);
vfprintf(stderr, str, args);
va_end(args);
24 years ago
my_perror();
24 years ago
fflush(stdout);
fflush(stderr);
24 years ago
return;
24 years ago
}
/*
* Fatal error. Print a message and terminate. Don't dump core and don't
* print the system's errno value.
*
* err_quit(str, arg1, arg2, ...)
*
* The string "str" must specify the conversion specification for any args.
*/
/* VARARGS1 */
void
err_quit(char *str, ...)
24 years ago
{
va_list args;
24 years ago
va_start(args, str);
vfprintf(stderr, str, args);
fputc('\n', stderr);
va_end(args);
24 years ago
exit(1);
24 years ago
}
/*
* Fatal error related to a system call. Print a message and terminate.
* Don't dump core, but do print the system's errno value and its associated
* message.
*
* err_sys(str, arg1, arg2, ...)
*
* The string "str" must specify the conversion specification for any args.
*/
/* VARARGS1 */
void
err_sys(char *str, ...)
24 years ago
{
va_list args;
24 years ago
va_start(args, str);
vfprintf(stderr, str, args);
va_end(args);
24 years ago
my_perror();
24 years ago
exit(1);
24 years ago
}
void
usage(poptContext context)
24 years ago
{
poptPrintUsage(context, stderr, 0);
fprintf(stderr, " hostname [plugin-options...]\n");
exit(1);
24 years ago
}
/*
* Return a string containing some additional operating-system dependent
* information. Note that different versions of UNIX assign different
* meanings to the same value of "errno" (compare errno's starting with 35
* between System V and BSD, for example). This means that if an error
* condition is being sent to another UNIX system, we must interpret the
* errno value on the system that generated the error, and not just send the
* decimal value of errno to the other system.
*/
char *
sys_err_str()
24 years ago
{
static char msgstr[200];
if (errno != 0) {
sprintf(msgstr, "(%s)", strerror(errno));
} else {
msgstr[0] = '\0';
}
return (msgstr);
24 years ago
}