xref: /titanic_44/usr/src/lib/krb5/ss/error.c (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
1 /*
2  * Copyright (c) 2000 by Sun Microsystems, Inc.
3  * All rights reserved.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * Copyright 1987, 1988, 1989 by MIT Student Information Processing
10  * Board
11  *
12  * For copyright information, see copyright.h.
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 "copyright.h"
29 #include "com_err.h"
30 #include "ss_internal.h"
31 
32 extern void com_err_va ();
33 
34 #undef ss_error
35 
36 char * ss_name(sci_idx)
37     int sci_idx;
38 {
39     register char *ret_val;
40     register ss_data *infop;
41 
42     infop = ss_info(sci_idx);
43     if (infop->current_request == (char const *)NULL) {
44 	ret_val = malloc((unsigned)
45 			 (strlen(infop->subsystem_name)+1)
46 			 * sizeof(char));
47 	if (ret_val == (char *)NULL)
48 	    return((char *)NULL);
49 	strcpy(ret_val, infop->subsystem_name);
50 	return(ret_val);
51     }
52     else {
53 	register char *cp;
54 	register char const *cp1;
55 	ret_val = malloc((unsigned)sizeof(char) *
56 			 (strlen(infop->subsystem_name)+
57 			  strlen(infop->current_request)+
58 			  4));
59 	cp = ret_val;
60 	cp1 = infop->subsystem_name;
61 	while (*cp1)
62 	    *cp++ = *cp1++;
63 	*cp++ = ' ';
64 	*cp++ = '(';
65 	cp1 = infop->current_request;
66 	while (*cp1)
67 	    *cp++ = *cp1++;
68 	*cp++ = ')';
69 	*cp = '\0';
70 	return(ret_val);
71     }
72 }
73 
74 #ifdef HAVE_STDARG_H
75 void ss_error (int sci_idx, long code, const char * fmt, ...)
76 #else
77 void ss_error (va_alist)
78     va_dcl
79 #endif
80 {
81     register char *whoami;
82     va_list pvar;
83 #ifndef HAVE_STDARG_H
84     int sci_idx;
85     long code;
86     char * fmt;
87     va_start (pvar);
88     sci_idx = va_arg (pvar, int);
89     code = va_arg (pvar, long);
90     fmt = va_arg (pvar, char *);
91 #else
92     va_start (pvar, fmt);
93 #endif
94     whoami = ss_name (sci_idx);
95     com_err_va (whoami, code, fmt, pvar);
96     free (whoami);
97     va_end(pvar);
98 }
99 
100 void ss_perror (sci_idx, code, msg) /* for compatibility */
101     int sci_idx;
102     long code;
103     char const *msg;
104 {
105     ss_error (sci_idx, code, "%s", msg);
106 }
107