diff options
Diffstat (limited to 'misc')
-rw-r--r-- | misc/strerror.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/misc/strerror.c b/misc/strerror.c new file mode 100644 index 000000000..acb81618c --- /dev/null +++ b/misc/strerror.c @@ -0,0 +1,22 @@ +#include<stdlib.h> +#include<errno.h> +#include<stdio.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]; +} |