e2fsprogs/lib/et/com_err.c

115 lines
2.2 KiB
C
Raw Normal View History

1997-04-26 17:21:57 +04:00
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board.
*
* For copyright info, see mit-sipb-copyright.h.
*/
#include <stdio.h>
1997-04-26 17:34:30 +04:00
#include "com_err.h"
1997-04-26 17:21:57 +04:00
#include "mit-sipb-copyright.h"
#include "error_table.h"
#include "internal.h"
1997-04-26 17:34:30 +04:00
#if !defined(__STDC__) && !defined(STDARG_PROTOTYPES)
#include <varargs.h>
#define VARARGS
1997-04-26 17:21:57 +04:00
#endif
static void
#ifdef __STDC__
1997-04-26 17:34:30 +04:00
default_com_err_proc (const char *whoami, errcode_t code, const
char *fmt, va_list args)
1997-04-26 17:21:57 +04:00
#else
default_com_err_proc (whoami, code, fmt, args)
const char *whoami;
1997-04-26 17:34:30 +04:00
errcode_t code;
1997-04-26 17:21:57 +04:00
const char *fmt;
va_list args;
#endif
{
if (whoami) {
fputs(whoami, stderr);
fputs(": ", stderr);
}
if (code) {
fputs(error_message(code), stderr);
fputs(" ", stderr);
}
if (fmt) {
vfprintf (stderr, fmt, args);
}
/* should do this only on a tty in raw mode */
putc('\r', stderr);
1997-04-26 17:34:30 +04:00
putc('\n', stderr);
1997-04-26 17:21:57 +04:00
fflush(stderr);
}
#ifdef __STDC__
1997-04-26 17:34:30 +04:00
typedef void (*errf) (const char *, errcode_t, const char *, va_list);
1997-04-26 17:21:57 +04:00
#else
typedef void (*errf) ();
#endif
errf com_err_hook = default_com_err_proc;
1997-04-26 17:34:30 +04:00
#ifdef __STDC__
void com_err_va (const char *whoami, errcode_t code, const char *fmt,
va_list args)
#else
1997-04-26 17:21:57 +04:00
void com_err_va (whoami, code, fmt, args)
const char *whoami;
1997-04-26 17:34:30 +04:00
errcode_t code;
1997-04-26 17:21:57 +04:00
const char *fmt;
va_list args;
1997-04-26 17:34:30 +04:00
#endif
1997-04-26 17:21:57 +04:00
{
(*com_err_hook) (whoami, code, fmt, args);
}
#ifndef VARARGS
void com_err (const char *whoami,
1997-04-26 17:34:30 +04:00
errcode_t code,
1997-04-26 17:21:57 +04:00
const char *fmt, ...)
{
#else
void com_err (va_alist)
va_dcl
{
const char *whoami, *fmt;
1997-04-26 17:34:30 +04:00
errcode_t code;
1997-04-26 17:21:57 +04:00
#endif
va_list pvar;
if (!com_err_hook)
com_err_hook = default_com_err_proc;
#ifdef VARARGS
va_start (pvar);
whoami = va_arg (pvar, const char *);
1997-04-26 17:34:30 +04:00
code = va_arg (pvar, errcode_t);
1997-04-26 17:21:57 +04:00
fmt = va_arg (pvar, const char *);
#else
va_start(pvar, fmt);
#endif
com_err_va (whoami, code, fmt, pvar);
va_end(pvar);
}
errf set_com_err_hook (new_proc)
errf new_proc;
{
errf x = com_err_hook;
if (new_proc)
com_err_hook = new_proc;
else
com_err_hook = default_com_err_proc;
return x;
}
errf reset_com_err_hook () {
errf x = com_err_hook;
com_err_hook = default_com_err_proc;
return x;
}