mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
Nicer output for negative error numbers in strerror_r
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
2011-05-21 Ulrich Drepper <drepper@gmail.com>
|
2011-05-21 Ulrich Drepper <drepper@gmail.com>
|
||||||
|
|
||||||
|
* string/_strerror.c (__strerror_r): Print negative errors as signed
|
||||||
|
numbers.
|
||||||
|
|
||||||
[BZ #12777]
|
[BZ #12777]
|
||||||
* iconvdata/cp1258.c (comp_table_data): Remove entry 0x00A5 0xEC.
|
* iconvdata/cp1258.c (comp_table_data): Remove entry 0x00A5 0xEC.
|
||||||
(decomp_table): Change U0385 entry to emit 0xA5 0xEC.
|
(decomp_table): Change U0385 entry to emit 0xA5 0xEC.
|
||||||
|
@ -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.
|
Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
@ -18,7 +18,9 @@
|
|||||||
02111-1307 USA. */
|
02111-1307 USA. */
|
||||||
|
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <stdio-common/_itoa.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. */
|
`int' of 8 bytes we never need more than 20 digits. */
|
||||||
char numbuf[21];
|
char numbuf[21];
|
||||||
const char *unk = _("Unknown error ");
|
const char *unk = _("Unknown error ");
|
||||||
const size_t unklen = strlen (unk);
|
size_t unklen = strlen (unk);
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
bool negative = errnum < 0;
|
||||||
|
|
||||||
numbuf[20] = '\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
|
/* Now construct the result while taking care for the destination
|
||||||
buffer size. */
|
buffer size. */
|
||||||
q = __mempcpy (buf, unk, MIN (unklen, buflen));
|
q = __mempcpy (buf, unk, MIN (unklen, buflen));
|
||||||
|
if (negative && unklen < buflen)
|
||||||
|
{
|
||||||
|
*q++ = '-';
|
||||||
|
++unklen;
|
||||||
|
}
|
||||||
if (unklen < buflen)
|
if (unklen < buflen)
|
||||||
memcpy (q, p, MIN ((size_t) (&numbuf[21] - p), buflen - unklen));
|
memcpy (q, p, MIN ((size_t) (&numbuf[21] - p), buflen - unklen));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user