diff options
author | Ulrich Drepper <drepper@gmail.com> | 2011-05-21 12:09:23 -0400 |
---|---|---|
committer | Ulrich Drepper <drepper@gmail.com> | 2011-05-21 12:09:23 -0400 |
commit | 7e4afad5bcf49e03c3b987399c6a8f66a9018660 (patch) | |
tree | 4773f1a9b6cdb4e3562c8bc968da552789f836b9 /string/_strerror.c | |
parent | 8e211fecca7bddfb03a3aed54a47c243afddc150 (diff) | |
download | glibc-7e4afad5bcf49e03c3b987399c6a8f66a9018660.zip glibc-7e4afad5bcf49e03c3b987399c6a8f66a9018660.tar.gz glibc-7e4afad5bcf49e03c3b987399c6a8f66a9018660.tar.bz2 |
Nicer output for negative error numbers in strerror_r
Diffstat (limited to 'string/_strerror.c')
-rw-r--r-- | string/_strerror.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/string/_strerror.c b/string/_strerror.c index cb5d9e3..ad9b148 100644 --- a/string/_strerror.c +++ b/string/_strerror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,93,95,96,97,98,2000,2002,2006 +/* Copyright (C) 1991,93,95,96,97,98,2000,2002,2006,2011 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -18,7 +18,9 @@ 02111-1307 USA. */ #include <libintl.h> +#include <stdbool.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/param.h> #include <stdio-common/_itoa.h> @@ -43,15 +45,21 @@ __strerror_r (int errnum, char *buf, size_t buflen) `int' of 8 bytes we never need more than 20 digits. */ char numbuf[21]; const char *unk = _("Unknown error "); - const size_t unklen = strlen (unk); + size_t unklen = strlen (unk); char *p, *q; + bool negative = errnum < 0; numbuf[20] = '\0'; - p = _itoa_word (errnum, &numbuf[20], 10, 0); + p = _itoa_word (abs (errnum), &numbuf[20], 10, 0); /* Now construct the result while taking care for the destination buffer size. */ q = __mempcpy (buf, unk, MIN (unklen, buflen)); + if (negative && unklen < buflen) + { + *q++ = '-'; + ++unklen; + } if (unklen < buflen) memcpy (q, p, MIN ((size_t) (&numbuf[21] - p), buflen - unklen)); |