]>
Commit | Line | Data |
---|---|---|
74015205 | 1 | /* Copyright (C) 1991, 93, 95, 96, 97, 98 Free Software Foundation, Inc. |
478b92f0 | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
478b92f0 UD |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public License as | |
6 | published by the Free Software Foundation; either version 2 of the | |
7 | License, or (at your option) any later version. | |
28f540f4 | 8 | |
478b92f0 UD |
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 | Library General Public License for more details. | |
28f540f4 | 13 | |
478b92f0 UD |
14 | You should have received a copy of the GNU Library General Public |
15 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
16 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 | Boston, MA 02111-1307, USA. */ | |
28f540f4 | 18 | |
46ec036d | 19 | #include <libintl.h> |
28f540f4 RM |
20 | #include <stdio.h> |
21 | #include <string.h> | |
74015205 UD |
22 | #include <sys/param.h> |
23 | #include <stdio-common/_itoa.h> | |
28f540f4 RM |
24 | |
25 | #ifndef HAVE_GNU_LD | |
310b3460 UD |
26 | # define _sys_errlist sys_errlist |
27 | # define _sys_nerr sys_nerr | |
28f540f4 RM |
28 | #endif |
29 | ||
6ed0492f UD |
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 | |
33 | always guaranteed. */ | |
34 | #ifndef dgettext | |
35 | # include <locale.h> /* We need LC_MESSAGES. */ | |
36 | # define dgettext(domainname, msgid) dcgettext (domainname, msgid, LC_MESSAGES) | |
37 | #endif | |
46ec036d | 38 | |
28f540f4 RM |
39 | /* Return a string describing the errno code in ERRNUM. */ |
40 | char * | |
310b3460 | 41 | __strerror_r (int errnum, char *buf, size_t buflen) |
28f540f4 | 42 | { |
86d2c878 | 43 | if (errnum < 0 || errnum >= _sys_nerr) |
28f540f4 | 44 | { |
74015205 UD |
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. */ | |
47 | char numbuf[21]; | |
6ed0492f | 48 | const char *unk = _("Unknown error "); |
86d2c878 | 49 | const size_t unklen = strlen (unk); |
74015205 UD |
50 | char *p, *q; |
51 | ||
52 | numbuf[20] = '\0'; | |
53 | p = _itoa_word (errnum, &numbuf[20], 10, 0); | |
54 | ||
55 | /* Now construct the result while taking care for the destination | |
56 | buffer size. */ | |
57 | q = __mempcpy (buf, unk, MIN (unklen, buflen)); | |
58 | if (unklen < buflen) | |
59 | __stpncpy (q, p, buflen - unklen); | |
60 | ||
61 | /* Terminate the string in any case. */ | |
62 | if (buflen > 0) | |
63 | buf[buflen - 1] = '\0'; | |
64 | ||
65 | return buf; | |
28f540f4 RM |
66 | } |
67 | ||
6ed0492f | 68 | return (char *) _(_sys_errlist[errnum]); |
28f540f4 | 69 | } |
310b3460 | 70 | weak_alias (__strerror_r, strerror_r) |