]> Savannah Git Hosting - gnulib.git/commitdiff
bitset: Don't access errno when it's not set.
authorBruno Haible <bruno@clisp.org>
Sun, 25 Feb 2024 15:12:57 +0000 (16:12 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 25 Feb 2024 15:12:57 +0000 (16:12 +0100)
* lib/bitset/stats.c (bitset_stats_read): Don't use errno after neither
fread() nor ferror() has set it. On native Windows, don't use errno
after fclose().

ChangeLog
lib/bitset/stats.c

index 511a9f247e0337a83b8b8f8031d5412722a68f43..270b8cb0aac0054c167a2b8e8616bab594add266 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-02-25  Bruno Haible  <bruno@clisp.org>
+
+       bitset: Don't access errno when it's not set.
+       * lib/bitset/stats.c (bitset_stats_read): Don't use errno after neither
+       fread() nor ferror() has set it. On native Windows, don't use errno
+       after fclose().
+
 2024-02-25  Bruno Haible  <bruno@clisp.org>
 
        bitset: Avoid newlines at the end of translatable strings.
index 5c40fc946627dc16c5af47e2bb2cfda60cadd3d7..c06a450f7cc4bf829ffd9af02d9fa5d3252dab6b 100644 (file)
@@ -261,12 +261,19 @@ bitset_stats_read (const char *file_name)
                  1, file) != 1)
         {
           if (ferror (file))
-            perror (_("cannot read stats file"));
+            fprintf (stderr, "%s\n", _("cannot read stats file"));
           else
             fprintf (stderr, "%s\n", _("bad stats file size"));
         }
       if (fclose (file) != 0)
-        perror (_("cannot read stats file"));
+        {
+#if defined _WIN32 && !defined __CYGWIN__
+          fprintf (stderr, "%s\n", _("cannot read stats file"));
+#else
+          /* fclose() sets errno.  */
+          perror (_("cannot read stats file"));
+#endif
+        }
     }
   bitset_stats_info_data.runs++;
 }