source: trunk/third/moira/util/et/com_err.c @ 24319

Revision 24319, 1.5 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
Line 
1/*
2 * Copyright 1987, 1988 by MIT Student Information Processing Board.
3 *
4 * For copyright info, see mit-sipb-copyright.h.
5 */
6
7#include "mit-sipb-copyright.h"
8
9#include <stdio.h>
10#include <stdarg.h>
11#include "error_table.h"
12#include "com_err.h"
13
14static const char rcsid[] = "$Id: com_err.c 3956 2010-01-05 20:56:56Z zacheiss $";
15
16static void default_com_err_proc(const char *progname, long code,
17                                 const char *fmt, va_list args);
18
19com_err_handler_t com_err_hook = default_com_err_proc;
20
21static void default_com_err_proc(const char *progname, long code,
22                                 const char *fmt, va_list args)
23{
24    if (progname) {
25        fputs(progname, stderr);
26        fputs(": ", stderr);
27    }
28
29    if (code) {
30        fputs(error_message(code), stderr);
31        fputs(" ", stderr);
32    }
33    if (fmt)
34        vfprintf(stderr, fmt, args);
35
36    /* possibly should do the \r only on a tty in raw mode */
37    putc('\r', stderr);
38    putc('\n', stderr);
39    fflush(stderr);
40}
41
42void com_err_va(const char *progname, long code, const char *fmt, va_list args)
43{
44    (*com_err_hook)(progname, code, fmt, args);
45}
46
47void com_err(const char *progname, long code, const char *fmt, ...)
48{
49    va_list pvar;
50
51    va_start(pvar, fmt);
52    com_err_va(progname, code, fmt, pvar);
53    va_end(pvar);
54}
55
56com_err_handler_t set_com_err_hook(com_err_handler_t new_proc)
57{
58    com_err_handler_t x = com_err_hook;
59
60    com_err_hook = (new_proc) ? new_proc : default_com_err_proc;
61    return x;
62}
63
64com_err_handler_t reset_com_err_hook()
65{
66    return set_com_err_hook(NULL);
67}
Note: See TracBrowser for help on using the repository browser.