xref: /onnv-gate/usr/src/cmd/sendmail/libsm/strerror.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3*0Sstevel@tonic-gate  *	All rights reserved.
4*0Sstevel@tonic-gate  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5*0Sstevel@tonic-gate  * Copyright (c) 1988, 1993
6*0Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
7*0Sstevel@tonic-gate  *
8*0Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
9*0Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
10*0Sstevel@tonic-gate  * the sendmail distribution.
11*0Sstevel@tonic-gate  *
12*0Sstevel@tonic-gate  */
13*0Sstevel@tonic-gate 
14*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #include <sm/gen.h>
17*0Sstevel@tonic-gate SM_RCSID("@(#)$Id: strerror.c,v 1.21 2001/06/17 21:31:41 ca Exp $")
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate /*
20*0Sstevel@tonic-gate **  define strerror for platforms that lack it.
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate 
23*0Sstevel@tonic-gate #include <errno.h>
24*0Sstevel@tonic-gate #include <stdio.h>	/* sys_errlist, on some platforms */
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate #include <sm/io.h>	/* sm_snprintf */
27*0Sstevel@tonic-gate #include <sm/string.h>
28*0Sstevel@tonic-gate #include <sm/conf.h>
29*0Sstevel@tonic-gate #include <sm/errstring.h>
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #if !defined(ERRLIST_PREDEFINED)
32*0Sstevel@tonic-gate extern char *sys_errlist[];
33*0Sstevel@tonic-gate extern int sys_nerr;
34*0Sstevel@tonic-gate #endif /* !defined(ERRLIST_PREDEFINED) */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #if !HASSTRERROR
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate **  STRERROR -- return error message string corresponding to an error number.
40*0Sstevel@tonic-gate **
41*0Sstevel@tonic-gate **	Parameters:
42*0Sstevel@tonic-gate **		err -- error number.
43*0Sstevel@tonic-gate **
44*0Sstevel@tonic-gate **	Returns:
45*0Sstevel@tonic-gate **		Error string (might be pointer to static buffer).
46*0Sstevel@tonic-gate */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate char *
strerror(err)49*0Sstevel@tonic-gate strerror(err)
50*0Sstevel@tonic-gate 	int err;
51*0Sstevel@tonic-gate {
52*0Sstevel@tonic-gate 	static char buf[64];
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate 	if (err >= 0 && err < sys_nerr)
55*0Sstevel@tonic-gate 		return (char *) sys_errlist[err];
56*0Sstevel@tonic-gate 	else
57*0Sstevel@tonic-gate 	{
58*0Sstevel@tonic-gate 		(void) sm_snprintf(buf, sizeof(buf), "Error %d", err);
59*0Sstevel@tonic-gate 		return buf;
60*0Sstevel@tonic-gate 	}
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate #endif /* !HASSTRERROR */
63