]> andersk Git - moira.git/blame - util/et/com_err.c
sync'ing files for RCS->CVS migration
[moira.git] / util / et / com_err.c
CommitLineData
d1b2a10e 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 <stdio.h>
8#include "mit-sipb-copyright.h"
9
10/*
11 * Our environment only provides for ANSI's <stdarg.h> when using GNU
12 * C. Grump grump...
13 */
14#if ! __GNUC__
15#define VARARGS 1
16#endif
17
18/* We don't have the v*printf routines... */
19#define vfprintf(stream,fmt,args) _doprnt(fmt,args,stream)
20
21#if __STDC__ && !VARARGS
22# include <stdarg.h>
23#else /* varargs: not STDC or no <stdarg> */
24 /* Non-ANSI, always take <varargs.h> path. */
25# undef VARARGS
26# define VARARGS 1
27# include <varargs.h>
28# undef vfprintf
29# define vfprintf(stream,fmt,args) _doprnt(fmt,args,stream)
30#endif /* varargs */
31
32#include "error_table.h"
33#include "internal.h"
34
35/*
36 * Protect us from header version (externally visible) of com_err, so
37 * we can survive in a <varargs.h> environment. I think.
38 */
39#define com_err com_err_external
40#include "com_err.h"
41#undef com_err
42
43/* BSD. sigh. */
44#undef vfprintf
45#define vfprintf(stream,fmt,args) _doprnt(fmt,args,stream)
46
47#if ! lint
48static const char rcsid[] =
49 "$Header$";
50#endif /* ! lint */
51
52static void
53#ifdef __STDC__
54 default_com_err_proc (const char *whoami, long code, const char *fmt, va_list args)
55#else
56 default_com_err_proc (whoami, code, fmt, args)
57 const char *whoami;
58 long code;
59 const char *fmt;
60 va_list args;
61#endif
62{
63 if (whoami) {
64 fputs(whoami, stderr);
65 fputs(": ", stderr);
66 }
67 if (code) {
68 fputs(error_message(code), stderr);
69 fputs(" ", stderr);
70 }
71 if (fmt) {
72 vfprintf (stderr, fmt, args);
73 }
74 putc('\n', stderr);
75 /* should do this only on a tty in raw mode */
76 putc('\r', stderr);
77 fflush(stderr);
78}
79
80#ifdef __STDC__
81typedef void (*errf) (const char *, long, const char *, va_list);
82#else
83typedef void (*errf) ();
84#endif
85
86errf com_err_hook = default_com_err_proc;
87
88void com_err_va (whoami, code, fmt, args)
89 const char *whoami;
90 long code;
91 const char *fmt;
92 va_list args;
93{
94 (*com_err_hook) (whoami, code, fmt, args);
95}
96
97#if ! VARARGS
98void com_err (const char *whoami,
99 long code,
100 const char *fmt, ...)
101{
102#else
103void com_err (va_alist)
104 va_dcl
105{
106 const char *whoami, *fmt;
107 long code;
108#endif
109 va_list pvar;
110
111 if (!com_err_hook)
112 com_err_hook = default_com_err_proc;
113#if VARARGS
114 va_start (pvar);
115 whoami = va_arg (pvar, const char *);
116 code = va_arg (pvar, long);
117 fmt = va_arg (pvar, const char *);
118#else
119 va_start(pvar, fmt);
120#endif
121 com_err_va (whoami, code, fmt, pvar);
122 va_end(pvar);
123}
124
125errf set_com_err_hook (new_proc)
126 errf new_proc;
127{
128 errf x = com_err_hook;
129 if (new_proc)
130 com_err_hook = new_proc;
131 else
132 com_err_hook = default_com_err_proc;
133 return x;
134}
135
136errf reset_com_err_hook () {
137 errf x = com_err_hook;
138 com_err_hook = default_com_err_proc;
139 return x;
140}
This page took 0.070782 seconds and 5 git commands to generate.