1 /* Copyright (C) 1991, 93, 95, 96, 97, 98, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <sys/param.h>
23 #include <stdio-common/_itoa.h>
26 # define _sys_errlist sys_errlist
27 # define _sys_nerr sys_nerr
30 /* It is critical here that we always use the `dcgettext' function for
31 the message translation. Since <libintl.h> only defines the macro
32 `dgettext' to use `dcgettext' for optimizing programs this is not
35 # include <locale.h> /* We need LC_MESSAGES. */
36 # define dgettext(domainname, msgid) dcgettext (domainname, msgid, LC_MESSAGES)
39 /* Return a string describing the errno code in ERRNUM. */
41 __strerror_r (int errnum
, char *buf
, size_t buflen
)
43 if (errnum
< 0 || errnum
>= _sys_nerr
|| _sys_errlist
[errnum
] == NULL
)
45 /* Buffer we use to print the number in. For a maximum size for
46 `int' of 8 bytes we never need more than 20 digits. */
48 const char *unk
= _("Unknown error ");
49 const size_t unklen
= strlen (unk
);
53 p
= _itoa_word (errnum
, &numbuf
[20], 10, 0);
55 /* Now construct the result while taking care for the destination
57 q
= __mempcpy (buf
, unk
, MIN (unklen
, buflen
));
59 memcpy (q
, p
, MIN ((size_t) (&numbuf
[21] - p
), buflen
- unklen
));
61 /* Terminate the string in any case. */
63 buf
[buflen
- 1] = '\0';
68 return (char *) _(_sys_errlist
[errnum
]);
70 weak_alias (__strerror_r
, strerror_r
)