bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/3] fprintftime: depend on stdio, not ignore-value


From: Paul Eggert
Subject: Re: [PATCH 1/3] fprintftime: depend on stdio, not ignore-value
Date: Fri, 04 Jan 2013 08:36:47 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

Instead of putting back that comment about the bug,
how about fixing the bug?  Something like the following.

Or perhaps a fix should be put into stdio.in.h so that
all gnulib programs can assume glibc behavior here,
for fwrite?  Though this would mean using an extern
function, something that caused trouble with libvirt...

diff --git a/lib/strftime.c b/lib/strftime.c
index 213ced8..b27b739 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -208,7 +208,7 @@ extern char *tzname[];
          else if (to_uppcase)                                                 \
            fwrite_uppcase (p, (s), _n);                                       \
          else                                                                 \
-           fwrite (s, _n, 1, p);                                              \
+           fwrite_asis (p, s, _n);                                            \
        }                                                                      \
      while (0)                                                                \
     )
@@ -306,6 +306,23 @@ fwrite_uppcase (FILE *fp, const CHAR_T *src, size_t len)
       ++src;
     }
 }
+
+static void
+fwrite_asis (FILE *fp, const CHAR_T *src, size_t len)
+{
+  /* POSIX and ISO C allow fwrite to fail due to ENOMEM *without*
+     setting the stream's error indicator.  Work around the problem
+     by invoking fwrite only on platforms we know are safe.  */
+#ifdef __GLIBC__
+  fwrite (src, len, 1, fp);
+#else
+  while (len-- > 0)
+    {
+      fputc (*src, fp);
+      ++src;
+    }
+#endif
+}
 #else
 static CHAR_T *
 memcpy_lowcase (CHAR_T *dest, const CHAR_T *src,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]