1 /* $Id: strerror.c 6127 2003-01-18 22:25:37Z rra $
3 ** Replacement for a missing strerror.
5 ** Written by Russ Allbery <rra@stanford.edu>
6 ** This work is hereby placed in the public domain by its author.
8 ** Provides the same functionality as the standard library routine strerror
9 ** for those platforms that don't have it (e.g. Ultrix). Assume that we
10 ** have sys_nerr and sys_errlist available to use instead. Calling
11 ** strerror should be thread-safe unless it is called for an unknown errno.
16 /* Our declarations of sys_nerr and sys_errlist may conflict with the ones
17 provided by stdio.h from glibc. This trick hides the declarations in the
18 system header from the compiler while we test. (The conflicts are just
19 whether or not to const, so there are no negative effects from using our
22 # define sys_nerr hidden_sys_nerr
23 # define sys_errlist hidden_sys_errlist
34 extern const int sys_nerr;
35 extern const char *sys_errlist[];
37 /* If we're running the test suite, rename strerror to avoid conflicts with
38 the system version. */
40 # define strerror test_strerror
41 const char *test_strerror(int);
42 int snprintf(char *, size_t, const char *, ...);
51 if (error >= 0 && error < sys_nerr)
52 return sys_errlist[error];
54 snprintf(buff, sizeof(buff), "Error code %d", error);