diff options
author | Bruno Haible <bruno@clisp.org> | 2019-10-28 01:23:33 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-10-28 01:23:33 +0100 |
commit | 645b1baf4e98ca8a9426b7a4263e001c0f14b7f9 (patch) | |
tree | be654e4a337ae785cae61a5975e8d34efb3c97ce /lib/textstyle.in.h | |
parent | bb0f6e99fdb3da658a5936c65af2085578847bc9 (diff) | |
download | gnulib-645b1baf4e98ca8a9426b7a4263e001c0f14b7f9.tar.gz |
libtextstyle-optional: Sync with current not-yet-released libtextstyle.
* lib/textstyle.in.h: Include <stdarg.h>.
(ostream_printf, ostream_vprintf): New functions.
* modules/libtextstyle-optional (Depends-on): Add vasprintf-posix.
Diffstat (limited to 'lib/textstyle.in.h')
-rw-r--r-- | lib/textstyle.in.h | 46 |
1 files changed, 46 insertions, 0 deletions
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 <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; |