xref: /titanic_52/usr/src/lib/libresolv2/common/bsd/strerror.c (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #if defined(LIBC_SCCS) && !defined(lint)
7 static const char sccsid[] = "@(#)strerror.c	8.1 (Berkeley) 6/4/93";
8 static const char rcsid[] = "$Id: strerror.c,v 8.7 2001/08/28 11:48:10 marka Exp $";
9 #endif /* LIBC_SCCS and not lint */
10 
11 /*
12  * Copyright (c) 1988, 1993
13  *    The Regents of the University of California.  All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  * 3. All advertising materials mentioning features or use of this software
24  *    must display the following acknowledgement:
25  * 	This product includes software developed by the University of
26  * 	California, Berkeley and its contributors.
27  * 4. Neither the name of the University nor the names of its contributors
28  *    may be used to endorse or promote products derived from this software
29  *    without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41  * SUCH DAMAGE.
42  */
43 
44 #pragma ident	"%Z%%M%	%I%	%E% SMI"
45 
46 #include "port_before.h"
47 
48 #include <sys/param.h>
49 #include <sys/types.h>
50 
51 #include <string.h>
52 
53 #include "port_after.h"
54 
55 #ifndef NEED_STRERROR
56 int __strerror_unneeded__;
57 #else
58 
59 #ifdef USE_SYSERROR_LIST
60 extern int sys_nerr;
61 extern char *sys_errlist[];
62 #endif
63 
64 const char *
65 isc_strerror(int num) {
66 #define	UPREFIX	"Unknown error: "
67 	static char ebuf[40] = UPREFIX;		/* 64-bit number + slop */
68 	u_int errnum;
69 	char *p, *t;
70 	const char *ret;
71 	char tmp[40];
72 
73 	errnum = num;				/* convert to unsigned */
74 #ifdef USE_SYSERROR_LIST
75 	if (errnum < sys_nerr)
76 		return (sys_errlist[errnum]);
77 #else
78 #undef strerror
79 	ret = strerror(num);			/* call strerror() in libc */
80 	if (ret != NULL)
81 		return(ret);
82 #endif
83 
84 	/* Do this by hand, so we don't include stdio(3). */
85 	t = tmp;
86 	do {
87 		*t++ = "0123456789"[errnum % 10];
88 	} while (errnum /= 10);
89 	for (p = ebuf + sizeof(UPREFIX) - 1;;) {
90 		*p++ = *--t;
91 		if (t <= tmp)
92 			break;
93 	}
94 	return (ebuf);
95 }
96 
97 #endif /*NEED_STRERROR*/
98