]> git.ozlabs.org Git - yaboot.git/blob - include/et/com_err.c
Commit yaboot 1.3.0
[yaboot.git] / include / et / com_err.c
1 /*
2  * Copyright 1987, 1988 by MIT Student Information Processing Board.
3  * 
4  * Permission to use, copy, modify, and distribute this software and
5  * its documentation for any purpose is hereby granted, provided that
6  * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7  * advertising or publicity pertaining to distribution of the software
8  * without specific, written prior permission.  M.I.T. and the
9  * M.I.T. S.I.P.B. make no representations about the suitability of
10  * this software for any purpose.  It is provided "as is" without
11  * express or implied warranty.
12  */
13
14 #include <stdio.h>
15 #include "com_err.h"
16 #include "error_table.h"
17 #include "internal.h"
18
19 #if !defined(__STDC__) && !defined(STDARG_PROTOTYPES)
20 #include <varargs.h>
21 #define VARARGS
22 #endif
23
24 static void
25 #ifdef __STDC__
26     default_com_err_proc (const char *whoami, errcode_t code, const
27                           char *fmt, va_list args)
28 #else
29     default_com_err_proc (whoami, code, fmt, args)
30     const char *whoami;
31     errcode_t code;
32     const char *fmt;
33     va_list args;
34 #endif
35 {
36     if (whoami) {
37         fputs(whoami, stderr);
38         fputs(": ", stderr);
39     }
40     if (code) {
41         fputs(error_message(code), stderr);
42         fputs(" ", stderr);
43     }
44     if (fmt) {
45         vfprintf (stderr, fmt, args);
46     }
47     /* should do this only on a tty in raw mode */
48     putc('\r', stderr);
49     putc('\n', stderr);
50     fflush(stderr);
51 }
52
53 #ifdef __STDC__
54 typedef void (*errf) (const char *, errcode_t, const char *, va_list);
55 #else
56 typedef void (*errf) ();
57 #endif
58
59 errf com_err_hook = default_com_err_proc;
60
61 #ifdef __STDC__
62 void com_err_va (const char *whoami, errcode_t code, const char *fmt,
63                  va_list args)
64 #else
65 void com_err_va (whoami, code, fmt, args)
66     const char *whoami;
67     errcode_t code;
68     const char *fmt;
69     va_list args;
70 #endif
71 {
72     (*com_err_hook) (whoami, code, fmt, args);
73 }
74
75 #ifndef VARARGS
76 void com_err (const char *whoami,
77               errcode_t code,
78               const char *fmt, ...)
79 {
80 #else
81 void com_err (va_alist)
82     va_dcl
83 {
84     const char *whoami, *fmt;
85     errcode_t code;
86 #endif
87     va_list pvar;
88
89     if (!com_err_hook)
90         com_err_hook = default_com_err_proc;
91 #ifdef VARARGS
92     va_start (pvar);
93     whoami = va_arg (pvar, const char *);
94     code = va_arg (pvar, errcode_t);
95     fmt = va_arg (pvar, const char *);
96 #else
97     va_start(pvar, fmt);
98 #endif
99     com_err_va (whoami, code, fmt, pvar);
100     va_end(pvar);
101 }
102
103 errf set_com_err_hook (new_proc)
104     errf new_proc;
105 {
106     errf x = com_err_hook;
107
108     if (new_proc)
109         com_err_hook = new_proc;
110     else
111         com_err_hook = default_com_err_proc;
112
113     return x;
114 }
115
116 errf reset_com_err_hook () {
117     errf x = com_err_hook;
118     com_err_hook = default_com_err_proc;
119     return x;
120 }