summaryrefslogtreecommitdiff
path: root/misc/strerror.c
blob: 39289231d90c207194abe49da9d3fa92d9931bbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "system.h"

extern int sys_nerr;
extern char *sys_errlist[];
static char buf[64];

char *
strerror(int errnum) 
{
  if (errnum < 0 || errnum > sys_nerr)
    {
      static char fmt[] = "Unknown error %d";
      size_t len = (size_t) sprintf (buf, fmt, errnum);
      if (len < (size_t) sizeof(fmt) - 2)
        return NULL;
      buf[len - 1] = '\0';
      return buf;
    }

  return (char *) sys_errlist[errnum];
}