Whamcloud - gitweb
80ebc823bf130c8a297c2cb081634ecaa4e21a0e
[tools/e2fsprogs.git] / lib / ss / error.c
1 /*
2  * Copyright 1987, 1988, 1989 by MIT Student Information Processing
3  * Board
4  *
5  * For copyright information, see copyright.h.
6  */
7
8 #include <stdio.h>
9
10 /*
11  * I'm assuming that com_err.h includes varargs.h, which it does
12  * (right now).  There really ought to be a way for me to include the
13  * file without worrying about whether com_err.h includes it or not,
14  * but varargs.h doesn't define anything that I can use as a flag, and
15  * gcc will lose if I try to include it twice and redefine stuff.
16  */
17 #if !defined(__STDC__) || !defined(ibm032) || !defined(NeXT)
18 #define ss_error ss_error_external
19 #endif
20
21 #include "copyright.h"
22 #include <com_err.h>
23 #include "ss_internal.h"
24
25 #ifdef HAVE_STDARG_H
26 #include <stdarg.h>
27 #else
28 #include <vararg.h>
29 #endif
30   
31 #undef ss_error
32
33 char * ss_name(sci_idx)
34     int sci_idx;
35 {
36     register char *ret_val;
37     register ss_data *infop;
38     
39     infop = ss_info(sci_idx);
40     if (infop->current_request == (char const *)NULL) {
41         ret_val = malloc((unsigned)
42                          (strlen(infop->subsystem_name)+1)
43                          * sizeof(char));
44         if (ret_val == (char *)NULL)
45             return((char *)NULL);
46         strcpy(ret_val, infop->subsystem_name);
47         return(ret_val);
48     }
49     else {
50         register char *cp;
51         register char const *cp1;
52         ret_val = malloc((unsigned)sizeof(char) * 
53                          (strlen(infop->subsystem_name)+
54                           strlen(infop->current_request)+
55                           4));
56         cp = ret_val;
57         cp1 = infop->subsystem_name;
58         while (*cp1)
59             *cp++ = *cp1++;
60         *cp++ = ' ';
61         *cp++ = '(';
62         cp1 = infop->current_request;
63         while (*cp1)
64             *cp++ = *cp1++;
65         *cp++ = ')';
66         *cp = '\0';
67         return(ret_val);
68     }
69 }
70
71 #ifdef HAVE_STDARG_H
72 void ss_error (int sci_idx, long code, const char * fmt, ...)
73 #else
74 void ss_error (va_alist)
75     va_dcl
76 #endif
77 {
78     register char const *whoami;
79     va_list pvar;
80 #ifndef HAVE_STDARG_H
81     int sci_idx;
82     long code;
83     char * fmt;
84     va_start (pvar);
85     sci_idx = va_arg (pvar, int);
86     code = va_arg (pvar, long);
87     fmt = va_arg (pvar, char *);
88 #else
89     va_start (pvar, fmt);
90 #endif
91     whoami = ss_name (sci_idx);
92     com_err_va (whoami, code, fmt, pvar);
93     free (whoami);
94     va_end(pvar);
95 }
96
97 void ss_perror (sci_idx, code, msg) /* for compatibility */
98     int sci_idx;
99     long code;
100     char const *msg;
101 {
102     ss_error (sci_idx, code, "%s", msg);
103 }