190792Sgshapiro/*
2261363Sgshapiro * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
390792Sgshapiro *	All rights reserved.
490792Sgshapiro * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
590792Sgshapiro * Copyright (c) 1988, 1993
690792Sgshapiro *	The Regents of the University of California.  All rights reserved.
790792Sgshapiro *
890792Sgshapiro * By using this file, you agree to the terms and conditions set
990792Sgshapiro * forth in the LICENSE file which can be found at the top level of
1090792Sgshapiro * the sendmail distribution.
1190792Sgshapiro *
1290792Sgshapiro */
1390792Sgshapiro
1490792Sgshapiro#include <sm/gen.h>
15266692SgshapiroSM_RCSID("@(#)$Id: strerror.c,v 1.24 2013-11-22 20:51:43 ca Exp $")
1690792Sgshapiro
1790792Sgshapiro/*
1890792Sgshapiro**  define strerror for platforms that lack it.
1990792Sgshapiro*/
2090792Sgshapiro
2190792Sgshapiro#include <errno.h>
2290792Sgshapiro#include <stdio.h>	/* sys_errlist, on some platforms */
2390792Sgshapiro
2490792Sgshapiro#include <sm/io.h>	/* sm_snprintf */
2590792Sgshapiro#include <sm/string.h>
2690792Sgshapiro#include <sm/conf.h>
2790792Sgshapiro#include <sm/errstring.h>
2890792Sgshapiro
2990792Sgshapiro#if !defined(ERRLIST_PREDEFINED)
3090792Sgshapiroextern char *sys_errlist[];
3190792Sgshapiroextern int sys_nerr;
3290792Sgshapiro#endif /* !defined(ERRLIST_PREDEFINED) */
3390792Sgshapiro
3490792Sgshapiro#if !HASSTRERROR
3590792Sgshapiro
3690792Sgshapiro/*
3790792Sgshapiro**  STRERROR -- return error message string corresponding to an error number.
3890792Sgshapiro**
3990792Sgshapiro**	Parameters:
4090792Sgshapiro**		err -- error number.
4190792Sgshapiro**
4290792Sgshapiro**	Returns:
4390792Sgshapiro**		Error string (might be pointer to static buffer).
4490792Sgshapiro*/
4590792Sgshapiro
4690792Sgshapirochar *
4790792Sgshapirostrerror(err)
4890792Sgshapiro	int err;
4990792Sgshapiro{
5090792Sgshapiro	static char buf[64];
5190792Sgshapiro
5290792Sgshapiro	if (err >= 0 && err < sys_nerr)
5390792Sgshapiro		return (char *) sys_errlist[err];
5490792Sgshapiro	else
5590792Sgshapiro	{
5690792Sgshapiro		(void) sm_snprintf(buf, sizeof(buf), "Error %d", err);
5790792Sgshapiro		return buf;
5890792Sgshapiro	}
5990792Sgshapiro}
6090792Sgshapiro#endif /* !HASSTRERROR */
61