From 645b1baf4e98ca8a9426b7a4263e001c0f14b7f9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 28 Oct 2019 01:23:33 +0100 Subject: [PATCH] libtextstyle-optional: Sync with current not-yet-released libtextstyle. * lib/textstyle.in.h: Include . (ostream_printf, ostream_vprintf): New functions. * modules/libtextstyle-optional (Depends-on): Add vasprintf-posix. --- lib/textstyle.in.h | 46 +++++++++++++++++++++++++++++++++++ modules/libtextstyle-optional | 1 + 2 files changed, 47 insertions(+) diff --git a/lib/textstyle.in.h b/lib/textstyle.in.h index fedc7d82a8..42abbab15c 100644 --- a/lib/textstyle.in.h +++ b/lib/textstyle.in.h @@ -31,6 +31,7 @@ #define _TEXTSTYLE_H #include +#include #include #include #include @@ -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; diff --git a/modules/libtextstyle-optional b/modules/libtextstyle-optional index f936986d74..2d55b3d76f 100644 --- a/modules/libtextstyle-optional +++ b/modules/libtextstyle-optional @@ -10,6 +10,7 @@ libtextstyle stdbool unistd fsync +vasprintf-posix configure.ac: gl_LIBTEXTSTYLE_OPTIONAL -- 2.39.5