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