]> Savannah Git Hosting - gnulib.git/commitdiff
libtextstyle-optional: Sync with current not-yet-released libtextstyle.
authorBruno Haible <bruno@clisp.org>
Mon, 28 Oct 2019 00:23:33 +0000 (01:23 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 28 Oct 2019 00:23:33 +0000 (01:23 +0100)
* lib/textstyle.in.h: Include <stdarg.h>.
(ostream_printf, ostream_vprintf): New functions.
* modules/libtextstyle-optional (Depends-on): Add vasprintf-posix.

lib/textstyle.in.h
modules/libtextstyle-optional

index fedc7d82a808e961f4754818b7df24a51cf1805f..42abbab15ca7f3121ca562f017dece453a818590 100644 (file)
@@ -31,6 +31,7 @@
 #define _TEXTSTYLE_H
 
 #include <errno.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -112,6 +113,51 @@ ostream_write_str (ostream_t stream, const char *string)
   ostream_write_mem (stream, string, strlen (string));
 }
 
+static inline ptrdiff_t ostream_printf (ostream_t stream,
+                                        const char *format, ...)
+#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3
+  __attribute__ ((__format__ (__printf__, 2, 3)))
+#endif
+  ;
+static inline ptrdiff_t
+ostream_printf (ostream_t stream, const char *format, ...)
+{
+  va_list args;
+  char *temp_string;
+  ptrdiff_t ret;
+
+  va_start (args, format);
+  ret = vasprintf (&temp_string, format, args);
+  va_end (args);
+  if (ret >= 0)
+    {
+      if (ret > 0)
+        ostream_write_str (stream, temp_string);
+      free (temp_string);
+    }
+  return ret;
+}
+
+static inline ptrdiff_t ostream_vprintf (ostream_t stream,
+                                         const char *format, va_list args)
+#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3
+  __attribute__ ((__format__ (__printf__, 2, 0)))
+#endif
+  ;
+static inline ptrdiff_t
+ostream_vprintf (ostream_t stream, const char *format, va_list args)
+{
+  char *temp_string;
+  ptrdiff_t ret = vasprintf (&temp_string, format, args);
+  if (ret >= 0)
+    {
+      if (ret > 0)
+        ostream_write_str (stream, temp_string);
+      free (temp_string);
+    }
+  return ret;
+}
+
 /* ------------------------- From styled-ostream.h ------------------------- */
 
 typedef ostream_t styled_ostream_t;
index f936986d740b023bd53637323438801c25e7a815..2d55b3d76f258b7f8258763763a3baf9b3d46e5d 100644 (file)
@@ -10,6 +10,7 @@ libtextstyle
 stdbool
 unistd
 fsync
+vasprintf-posix
 
 configure.ac:
 gl_LIBTEXTSTYLE_OPTIONAL