From 0faf882de6de6c1ec26aace9a9939914b40e7b89 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 1 Oct 2018 21:10:59 -0700 Subject: Use vasprintf(), if available, to implement dsprintf() Signed-off-by: Alan Coopersmith --- configure.ac | 3 +++ list.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/configure.ac b/configure.ac index 177e739..136353a 100644 --- a/configure.ac +++ b/configure.ac @@ -51,6 +51,9 @@ if test "x$with_bzip2" = xyes; then AC_DEFINE(X_BZIP2_FONT_COMPRESSION,1,[Support bzip2 for bitmap fonts]) fi +# Checks for system functions / libraries +AC_CHECK_FUNCS([vasprintf]) + # Checks for pkg-config packages PKG_CHECK_MODULES(MKFONTSCALE, fontenc freetype2) PKG_CHECK_MODULES(X11, [xproto >= 7.0.25]) diff --git a/list.c b/list.c index 320ce20..091d9c5 100644 --- a/list.c +++ b/list.c @@ -20,6 +20,8 @@ THE SOFTWARE. */ +#include "config.h" + #include #include #include @@ -63,6 +65,13 @@ dsprintf(const char *f, ...) { va_list args; char *string; +#ifdef HAVE_VASPRINTF + va_start(args, f); + if (vasprintf(&string, f, args) == -1) + string = NULL; + va_end(args); + return string; +#else { int n, size = 20; while(1) { @@ -83,6 +92,7 @@ dsprintf(const char *f, ...) free(string); } } +#endif } -- cgit v1.2.3