summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/_strerror.c14
-rw-r--r--sysdeps/mach/_strerror.c6
2 files changed, 11 insertions, 9 deletions
diff --git a/sysdeps/generic/_strerror.c b/sysdeps/generic/_strerror.c
index 72ebb216bf..569f7018e5 100644
--- a/sysdeps/generic/_strerror.c
+++ b/sysdeps/generic/_strerror.c
@@ -18,6 +18,7 @@ Cambridge, MA 02139, USA.  */
 
 #include <stdio.h>
 #include <string.h>
+#include "../stdio-common/_itoa.h"
 
 #ifndef HAVE_GNU_LD
 #define _sys_errlist sys_errlist
@@ -31,13 +32,14 @@ _strerror_internal (errnum, buf, buflen)
      char *buf;
      size_t buflen;
 {
-  if (errnum < 0 || errnum > _sys_nerr)
+  if (errnum < 0 || errnum >= _sys_nerr)
     {
-      int len = __snprintf (buf, buflen, _("Unknown error %d"), errnum);
-      if (len < 0)
-	return NULL;
-      buf[len - 1] = '\0';
-      return buf;
+      const char *unk = _("Unknown error ");
+      const size_t unklen = strlen (unk);
+      char *p = buf + buflen;
+      *--p = '\0';
+      p = _itoa (errnum, p, 10, 0);
+      return memcpy (p - unklen, unk, unklen);
     }
 
   return (char *) _(_sys_errlist[errnum]);
diff --git a/sysdeps/mach/_strerror.c b/sysdeps/mach/_strerror.c
index 82d83a048f..8b32f052e5 100644
--- a/sysdeps/mach/_strerror.c
+++ b/sysdeps/mach/_strerror.c
@@ -26,7 +26,7 @@ Cambridge, MA 02139, USA.  */
 char *
 _strerror_internal (int errnum, char *buf, size_t buflen)
 {
-  int system; 
+  int system;
   int sub;
   int code;
   const struct error_system *es;
@@ -43,7 +43,7 @@ _strerror_internal (int errnum, char *buf, size_t buflen)
       const char *unk = _("Error in unknown error system: ");
       const size_t unklen = strlen (unk);
       char *p = buf + buflen;
-      *p-- = '\0';
+      *--p = '\0';
       p = _itoa (errnum, p, 16, 1);
       return memcpy (p - unklen, unk, unklen);
     }
@@ -59,7 +59,7 @@ _strerror_internal (int errnum, char *buf, size_t buflen)
       const size_t unklen = strlen (unk);
       char *p = buf + buflen;
       size_t len = strlen (es->subsystem[sub].subsys_name);
-      *p-- = '\0';
+      *--p = '\0';
       p = _itoa (errnum, p, 16, 1);
       *p-- = ' ';
       p = memcpy (p - len, es->subsystem[sub].subsys_name, len);