From: Ulrich Drepper Date: Sat, 21 May 2011 20:19:06 +0000 (-0400) Subject: Fix last change X-Git-Tag: glibc-2.14~44 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=adcd5c15d2a37794d021104160b425ff61f88219;p=platform%2Fupstream%2Fglibc.git Fix last change And optimize a bit. --- diff --git a/string/xpg-strerror.c b/string/xpg-strerror.c index 00256c3..10fc1bf 100644 --- a/string/xpg-strerror.c +++ b/string/xpg-strerror.c @@ -19,20 +19,10 @@ #include #include -#include #include #include #include -#include -/* It is critical here that we always use the `dcgettext' function for - the message translation. Since only defines the macro - `dgettext' to use `dcgettext' for optimizing programs this is not - always guaranteed. */ -#ifndef dgettext -# include /* 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. */ int @@ -41,13 +31,18 @@ __xpg_strerror_r (int errnum, char *buf, size_t buflen) const char *estr = __strerror_r (errnum, buf, buflen); size_t estrlen = strlen (estr); - if (errnum < 0 || errnum >= _sys_nerr_internal - || _sys_errlist_internal[errnum] == NULL) - return EINVAL; - - assert (estr != buf); -/* Terminate the string in any case. */ - *((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0'; + if (estr == buf) + { + 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); + + /* Terminate the string in any case. */ + if (buflen > 0) + *((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0'; return buflen <= estrlen ? ERANGE : 0; }