xref: /freebsd/contrib/sendmail/libsm/strerror.c (revision e2c0e292e8a7ca00ba99bcfccc9e637f45c3e8b1)
140266059SGregory Neil Shapiro /*
25dd76dd0SGregory Neil Shapiro  * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
340266059SGregory Neil Shapiro  *	All rights reserved.
440266059SGregory Neil Shapiro  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
540266059SGregory Neil Shapiro  * Copyright (c) 1988, 1993
640266059SGregory Neil Shapiro  *	The Regents of the University of California.  All rights reserved.
740266059SGregory Neil Shapiro  *
840266059SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
940266059SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
1040266059SGregory Neil Shapiro  * the sendmail distribution.
1140266059SGregory Neil Shapiro  *
1240266059SGregory Neil Shapiro  */
1340266059SGregory Neil Shapiro 
1440266059SGregory Neil Shapiro #include <sm/gen.h>
154313cc83SGregory Neil Shapiro SM_RCSID("@(#)$Id: strerror.c,v 1.24 2013-11-22 20:51:43 ca Exp $")
1640266059SGregory Neil Shapiro 
1740266059SGregory Neil Shapiro /*
1840266059SGregory Neil Shapiro **  define strerror for platforms that lack it.
1940266059SGregory Neil Shapiro */
2040266059SGregory Neil Shapiro 
2140266059SGregory Neil Shapiro #include <errno.h>
2240266059SGregory Neil Shapiro #include <stdio.h>	/* sys_errlist, on some platforms */
2340266059SGregory Neil Shapiro 
2440266059SGregory Neil Shapiro #include <sm/io.h>	/* sm_snprintf */
2540266059SGregory Neil Shapiro #include <sm/string.h>
2640266059SGregory Neil Shapiro #include <sm/conf.h>
2740266059SGregory Neil Shapiro #include <sm/errstring.h>
2840266059SGregory Neil Shapiro 
2940266059SGregory Neil Shapiro #if !defined(ERRLIST_PREDEFINED)
3040266059SGregory Neil Shapiro extern char *sys_errlist[];
3140266059SGregory Neil Shapiro extern int sys_nerr;
32*5b0945b5SGregory Neil Shapiro #endif
3340266059SGregory Neil Shapiro 
3440266059SGregory Neil Shapiro #if !HASSTRERROR
3540266059SGregory Neil Shapiro 
3640266059SGregory Neil Shapiro /*
3740266059SGregory Neil Shapiro **  STRERROR -- return error message string corresponding to an error number.
3840266059SGregory Neil Shapiro **
3940266059SGregory Neil Shapiro **	Parameters:
4040266059SGregory Neil Shapiro **		err -- error number.
4140266059SGregory Neil Shapiro **
4240266059SGregory Neil Shapiro **	Returns:
4340266059SGregory Neil Shapiro **		Error string (might be pointer to static buffer).
4440266059SGregory Neil Shapiro */
4540266059SGregory Neil Shapiro 
4640266059SGregory Neil Shapiro char *
strerror(err)4740266059SGregory Neil Shapiro strerror(err)
4840266059SGregory Neil Shapiro 	int err;
4940266059SGregory Neil Shapiro {
5040266059SGregory Neil Shapiro 	static char buf[64];
5140266059SGregory Neil Shapiro 
5240266059SGregory Neil Shapiro 	if (err >= 0 && err < sys_nerr)
5340266059SGregory Neil Shapiro 		return (char *) sys_errlist[err];
5440266059SGregory Neil Shapiro 	else
5540266059SGregory Neil Shapiro 	{
5640266059SGregory Neil Shapiro 		(void) sm_snprintf(buf, sizeof(buf), "Error %d", err);
5740266059SGregory Neil Shapiro 		return buf;
5840266059SGregory Neil Shapiro 	}
5940266059SGregory Neil Shapiro }
6040266059SGregory Neil Shapiro #endif /* !HASSTRERROR */
61