mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-01 13:17:19 +08:00
Fix last change
And optimize a bit.
This commit is contained in:
parent
7ea72f9996
commit
adcd5c15d2
@ -19,20 +19,10 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libintl.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <stdio-common/_itoa.h>
|
|
||||||
|
|
||||||
/* It is critical here that we always use the `dcgettext' function for
|
|
||||||
the message translation. Since <libintl.h> only defines the macro
|
|
||||||
`dgettext' to use `dcgettext' for optimizing programs this is not
|
|
||||||
always guaranteed. */
|
|
||||||
#ifndef dgettext
|
|
||||||
# include <locale.h> /* We need LC_MESSAGES. */
|
|
||||||
# define dgettext(domainname, msgid) dcgettext (domainname, msgid, LC_MESSAGES)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Fill buf with a string describing the errno code in ERRNUM. */
|
/* Fill buf with a string describing the errno code in ERRNUM. */
|
||||||
int
|
int
|
||||||
@ -41,13 +31,18 @@ __xpg_strerror_r (int errnum, char *buf, size_t buflen)
|
|||||||
const char *estr = __strerror_r (errnum, buf, buflen);
|
const char *estr = __strerror_r (errnum, buf, buflen);
|
||||||
size_t estrlen = strlen (estr);
|
size_t estrlen = strlen (estr);
|
||||||
|
|
||||||
if (errnum < 0 || errnum >= _sys_nerr_internal
|
if (estr == buf)
|
||||||
|| _sys_errlist_internal[errnum] == NULL)
|
{
|
||||||
return EINVAL;
|
assert (errnum < 0 || errnum >= _sys_nerr_internal
|
||||||
|
|| _sys_errlist_internal[errnum] == NULL);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
assert (errnum >= 0 && errnum < _sys_nerr_internal
|
||||||
|
&& _sys_errlist_internal[errnum] != NULL);
|
||||||
|
|
||||||
assert (estr != buf);
|
/* Terminate the string in any case. */
|
||||||
/* Terminate the string in any case. */
|
if (buflen > 0)
|
||||||
*((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0';
|
*((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0';
|
||||||
|
|
||||||
return buflen <= estrlen ? ERANGE : 0;
|
return buflen <= estrlen ? ERANGE : 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user