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