summaryrefslogtreecommitdiff
path: root/com32/lib/strerror.c
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lib/strerror.c')
-rw-r--r--com32/lib/strerror.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/com32/lib/strerror.c b/com32/lib/strerror.c
index 8dbe74ad..1b3d4452 100644
--- a/com32/lib/strerror.c
+++ b/com32/lib/strerror.c
@@ -6,18 +6,26 @@
char *strerror(int errnum)
{
- static char message[32] = "error "; /* enough for error 2^63-1 */
+ static char message[32] = "error "; /* enough for error 2^63-1 */
+ char numbuf[32];
+ char *p;
+ unsigned int e = (unsigned int)errnum;
- char numbuf[32];
- char *p;
+ extern const int sys_nerr;
+ extern const char *const sys_errlist[];
- p = numbuf + sizeof numbuf;
- *--p = '\0';
+ if (e < (unsigned int)sys_nerr && sys_errlist[e])
+ return (char *)sys_errlist[e];
- do {
- *--p = (errnum % 10) + '0';
- errnum /= 10;
- } while (errnum);
+ p = numbuf + sizeof numbuf;
+ *--p = '\0';
- return (char *)memcpy(message + 6, p, (numbuf + sizeof numbuf) - p);
+ do {
+ *--p = (e % 10) + '0';
+ e /= 10;
+ } while (e);
+
+ memcpy(message + 6, p, (numbuf + sizeof numbuf) - p);
+
+ return message;
}