aboutsummaryrefslogtreecommitdiff
path: root/src/port/strerror.c
blob: daa97a803a9e6bb4dce2dae59a2b4df48af5aacf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* $Id: strerror.c,v 1.2 2003/07/28 00:09:16 tgl Exp $ */

/*
 * strerror - map error number to descriptive string
 *
 * This version is obviously somewhat Unix-specific.
 *
 * based on code by Henry Spencer
 * modified for ANSI by D'Arcy J.M. Cain
 */

#include <string.h>
#include <stdio.h>
#include <errno.h>

extern const char *const sys_errlist[];
extern int	sys_nerr;

const char *
strerror(int errnum)
{
	static char buf[24];

	if (errnum < 0 || errnum > sys_nerr)
	{
		sprintf(buf, "unrecognized error %d", errnum);
		return buf;
	}

	return sys_errlist[errnum];
}