]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgettextpo: Use a multithread-safe alternative to strerror().
authorBruno Haible <bruno@clisp.org>
Wed, 7 Aug 2024 18:04:26 +0000 (20:04 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 7 Aug 2024 18:04:26 +0000 (20:04 +0200)
* 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.

autogen.sh
gettext-tools/src/read-po-lex.c
gettext-tools/src/read-properties.c
gettext-tools/src/read-stringtable.c
gettext-tools/src/write-catalog.c
gnulib-local/lib/markup.c
gnulib-local/modules/markup

index b1c71d00dcb59d9be68ca29709c11b979abcbb9e..9d092645b1ba9f92dfc10b886edefd6a2ecd060e 100755 (executable)
@@ -398,6 +398,7 @@ if ! $skip_gnulib; then
     xalloc
     xconcat-filename
     xmalloca
+    xstrerror
     xstriconv
     xvasprintf
   '
index 8172b72476c9144e9e574262a74c569b892df027..5ca52f00d8130b48f53fdf612293b54fb6eddcc0 100644 (file)
@@ -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;
         }
index 2ae12fae0380b19166a6e41e554b71ece580fd75..8273e96fb3cb481e002ed6bd833f580782273ea6 100644 (file)
@@ -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;
     }
 
index 986ec02972aef18accf5e7d71faf6158d0eaced0..602cd3c53c60d7ee29cd837ff9a50b59b149b7f5 100644 (file)
@@ -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;
     }
index b0a7451f5a57dc7e7fa183490f624c57e41154d3..2b755e137ece0de78461c81b1388b979cb262d5e 100644 (file)
@@ -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));
         }
     }
 }
index 98d8e1f23060fbc869284f3970b795069ac61018..edc169ee4f7113f8a4319ce82e2a6f77bfc13f03 100644 (file)
@@ -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);
index 8d969d4f834fb8693f051a15e12c1573bb8cf207..cba9d2de7c67e9c79e019045bb2d1bbb44ad66e6 100644 (file)
@@ -14,6 +14,7 @@ unictype/ctype-alpha
 xalloc
 xlist
 xvasprintf
+xstrerror
 
 configure.ac: