1 /* Return diagnostic string based on error code.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
20 #include "xstrerror.h"
24 #include "xvasprintf.h"
28 #define _(msgid) gettext (msgid)
31 xstrerror (const char *message
, int errnum
)
33 /* Get the internationalized description of errnum,
34 in a stack-allocated buffer. */
37 #if !GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P
38 errdesc
= strerror_r (errnum
, errbuf
, sizeof errbuf
);
40 if (strerror_r (errnum
, errbuf
, sizeof errbuf
) == 0)
46 errdesc
= _("Unknown system error");
50 /* Allow e.g. French translators to insert a space before the colon. */
51 char *result
= xasprintf (_("%s: %s"), message
, errdesc
);
53 /* Probably a buggy translation. Use a safe fallback. */
54 result
= xasprintf ("%s%s%s", message
, ": ", errdesc
);
58 return xstrdup (errdesc
);