~ubuntu-branches/ubuntu/precise/eglibc/precise-201308281639

« back to all changes in this revision

Viewing changes to string/xpg-strerror.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-02-08 01:58:09 UTC
  • mfrom: (1.5.3) (288.1.12 precise)
  • Revision ID: package-import@ubuntu.com-20120208015809-ulscst7uteq3e22z
Tags: 2.15~pre6-0ubuntu10
Merge from Debian (r5151, 2.13-26).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2010
 
1
/* Copyright (C) 1991, 1993, 1995-1998, 2000, 2002, 2004, 2010, 2011
2
2
   Free Software Foundation, Inc.
3
3
   This file is part of the GNU C Library.
4
4
 
17
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
18
   02111-1307 USA.  */
19
19
 
 
20
#include <assert.h>
20
21
#include <errno.h>
21
 
#include <libintl.h>
22
22
#include <stdio.h>
23
23
#include <string.h>
24
24
#include <sys/param.h>
25
 
#include <stdio-common/_itoa.h>
26
25
 
27
 
/* It is critical here that we always use the `dcgettext' function for
28
 
   the message translation.  Since <libintl.h> only defines the macro
29
 
   `dgettext' to use `dcgettext' for optimizing programs this is not
30
 
   always guaranteed.  */
31
 
#ifndef dgettext
32
 
# include <locale.h>            /* We need LC_MESSAGES.  */
33
 
# define dgettext(domainname, msgid) dcgettext (domainname, msgid, LC_MESSAGES)
34
 
#endif
35
26
 
36
27
/* Fill buf with a string describing the errno code in ERRNUM.  */
37
28
int
38
29
__xpg_strerror_r (int errnum, char *buf, size_t buflen)
39
30
{
40
 
  if (errnum < 0 || errnum >= _sys_nerr_internal
41
 
      || _sys_errlist_internal[errnum] == NULL)
42
 
    return EINVAL;
43
 
 
44
 
  const char *estr = (const char *) _(_sys_errlist_internal[errnum]);
45
 
  size_t estrlen = strlen (estr) + 1;
46
 
 
47
 
  if (buflen < estrlen)
48
 
    return ERANGE;
49
 
 
50
 
  memcpy (buf, estr, estrlen);
51
 
  return 0;
 
31
  const char *estr = __strerror_r (errnum, buf, buflen);
 
32
  size_t estrlen = strlen (estr);
 
33
 
 
34
  if (estr == buf)
 
35
    {
 
36
      assert (errnum < 0 || errnum >= _sys_nerr_internal
 
37
              || _sys_errlist_internal[errnum] == NULL);
 
38
      return EINVAL;
 
39
    }
 
40
  assert (errnum >= 0 && errnum < _sys_nerr_internal
 
41
          && _sys_errlist_internal[errnum] != NULL);
 
42
 
 
43
  /* Terminate the string in any case.  */
 
44
  if (buflen > 0)
 
45
    *((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0';
 
46
 
 
47
  return buflen <= estrlen ? ERANGE : 0;
52
48
}