From: Bruno Haible Date: Wed, 7 Aug 2024 18:04:26 +0000 (+0200) Subject: libgettextpo: Use a multithread-safe alternative to strerror(). X-Git-Tag: v0.23~178 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d65c188776a7fd1022700cf779f21faadabaf21c;p=thirdparty%2Fgettext.git libgettextpo: Use a multithread-safe alternative to strerror(). * autogen.sh (GNULIB_MODULES_LIBGETTEXTPO): Add xstrerror. * gnulib-local/lib/markup.c: Include xstrerror.h. (unescape_string_inplace): Use xstrerror instead of strerror. * gnulib-local/modules/markup (Depends-on): Add xstrerror. * gettext-tools/src/read-po-lex.c: Include xstrerror.h. (mbfile_getc, lex_getc): Use xstrerror instead of strerror. * gettext-tools/src/read-properties.c: Include xstrerror.h. (properties_parse): Use xstrerror instead of strerror. * gettext-tools/src/read-stringtable.c: Include xstrerror.h. (phase1_getc): Use xstrerror instead of strerror. * gettext-tools/src/write-catalog.c: Include xstrerror.h. (msgdomain_list_print): Use xstrerror instead of strerror. --- diff --git a/autogen.sh b/autogen.sh index b1c71d00d..9d092645b 100755 --- a/autogen.sh +++ b/autogen.sh @@ -398,6 +398,7 @@ if ! $skip_gnulib; then xalloc xconcat-filename xmalloca + xstrerror xstriconv xvasprintf ' diff --git a/gettext-tools/src/read-po-lex.c b/gettext-tools/src/read-po-lex.c index 8172b7247..5ca52f00d 100644 --- a/gettext-tools/src/read-po-lex.c +++ b/gettext-tools/src/read-po-lex.c @@ -44,6 +44,7 @@ #include "po-charset.h" #include "xalloc.h" #include "xvasprintf.h" +#include "xstrerror.h" #include "po-error.h" #include "xerror-handler.h" #include "xmalloca.h" @@ -704,12 +705,10 @@ mbfile_getc (struct po_parser_state *ps, mbchar_t mbc, mbfile_t mbf) } else { - const char *errno_description = strerror (errno); + int err = errno; ps->catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - _("iconv failure"), - errno_description)); + xstrerror (_("iconv failure"), err)); } } else @@ -864,13 +863,12 @@ lex_getc (struct po_parser_state *ps, mbchar_t mbc) if (ferror (ps->mbf->fp)) bomb: { - const char *errno_description = strerror (errno); + int err = errno; ps->catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), + xstrerror (xasprintf (_("error while reading \"%s\""), ps->gram_pos.file_name), - errno_description)); + err)); } break; } diff --git a/gettext-tools/src/read-properties.c b/gettext-tools/src/read-properties.c index 2ae12fae0..8273e96fb 100644 --- a/gettext-tools/src/read-properties.c +++ b/gettext-tools/src/read-properties.c @@ -34,6 +34,7 @@ #include "read-catalog-abstract.h" #include "xalloc.h" #include "xvasprintf.h" +#include "xstrerror.h" #include "xerror-handler.h" #include "msgl-ascii.h" #include "read-file.h" @@ -592,12 +593,11 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file, contents = fread_file (file, 0, &contents_length); if (contents == NULL) { - const char *errno_description = strerror (errno); + int err = errno; catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), + xstrerror (xasprintf (_("error while reading \"%s\""), real_filename), - errno_description)); + err)); return; } diff --git a/gettext-tools/src/read-stringtable.c b/gettext-tools/src/read-stringtable.c index 986ec0297..602cd3c53 100644 --- a/gettext-tools/src/read-stringtable.c +++ b/gettext-tools/src/read-stringtable.c @@ -34,6 +34,7 @@ #include "read-catalog-abstract.h" #include "xalloc.h" #include "xvasprintf.h" +#include "xstrerror.h" #include "xerror-handler.h" #include "unistr.h" #include "gettext.h" @@ -92,12 +93,11 @@ phase1_getc (abstract_catalog_reader_ty *catr) { if (ferror (fp)) { - const char *errno_description = strerror (errno); + int err = errno; catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), + xstrerror (xasprintf (_("error while reading \"%s\""), real_file_name), - errno_description)); + err)); } return EOF; } diff --git a/gettext-tools/src/write-catalog.c b/gettext-tools/src/write-catalog.c index b0a7451f5..2b755e137 100644 --- a/gettext-tools/src/write-catalog.c +++ b/gettext-tools/src/write-catalog.c @@ -37,6 +37,7 @@ #include "fwriteerror.h" #include "xvasprintf.h" +#include "xstrerror.h" #include "xerror-handler.h" #include "gettext.h" @@ -218,12 +219,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd < 0) { - const char *errno_description = strerror (errno); + int err = errno; xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("cannot create output file \"%s\""), + xstrerror (xasprintf (_("cannot create output file \"%s\""), filename), - errno_description)); + err)); } } else @@ -243,12 +243,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, /* Make sure nothing went wrong. */ if (close (fd) < 0) { - const char *errno_description = strerror (errno); + int err = errno; xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while writing \"%s\" file"), + xstrerror (xasprintf (_("error while writing \"%s\" file"), filename), - errno_description)); + err)); } } else @@ -263,12 +262,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, fp = fopen (filename, "wb"); if (fp == NULL) { - const char *errno_description = strerror (errno); + int err = errno; xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("cannot create output file \"%s\""), + xstrerror (xasprintf (_("cannot create output file \"%s\""), filename), - errno_description)); + err)); } } else @@ -317,12 +315,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, /* Make sure nothing went wrong. */ if (fwriteerror (fp)) { - const char *errno_description = strerror (errno); + int err = errno; xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while writing \"%s\" file"), + xstrerror (xasprintf (_("error while writing \"%s\" file"), filename), - errno_description)); + err)); } } } diff --git a/gnulib-local/lib/markup.c b/gnulib-local/lib/markup.c index 98d8e1f23..edc169ee4 100644 --- a/gnulib-local/lib/markup.c +++ b/gnulib-local/lib/markup.c @@ -1,5 +1,5 @@ /* markup.c -- simple XML-like parser - Copyright (C) 2015, 2018, 2020 Free Software Foundation, Inc. + Copyright (C) 2015-2024 Free Software Foundation, Inc. This file is not part of the GNU gettext program, but is used with GNU gettext. @@ -48,6 +48,7 @@ #include "unistr.h" #include "xalloc.h" #include "xvasprintf.h" +#include "xstrerror.h" #define _(s) gettext(s) @@ -522,7 +523,7 @@ unescape_string_inplace (markup_parse_context_ty *context, char *error_text = xasprintf (_("invalid character reference: %s"), errno != 0 - ? strerror (errno) + ? xstrerror (NULL, errno) : _("not a valid number specification")); emit_error (context, error_text); free (error_text); diff --git a/gnulib-local/modules/markup b/gnulib-local/modules/markup index 8d969d4f8..cba9d2de7 100644 --- a/gnulib-local/modules/markup +++ b/gnulib-local/modules/markup @@ -14,6 +14,7 @@ unictype/ctype-alpha xalloc xlist xvasprintf +xstrerror configure.ac: