From edafda534244e3760000faf7a088af872d146325 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 1 Oct 2004 10:26:52 +0000 Subject: [PATCH] Fixes, mostly from Simon Josefsson. --- lib/ChangeLog | 6 ++++-- lib/snprintf.c | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index f92f90831d..a701b151fb 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,6 +1,8 @@ -2004-10-01 Bruno Haible +2004-10-01 Simon Josefsson + Bruno Haible - * snprintf.c: Include . + * snprintf.c: Include , , . + (snprintf): Declare 'args'. 2004-09-30 Simon Josefsson diff --git a/lib/snprintf.c b/lib/snprintf.c index 417dd33e19..92c265289a 100644 --- a/lib/snprintf.c +++ b/lib/snprintf.c @@ -20,10 +20,14 @@ # include #endif -/* Get specification. */ +/* Specification. */ #include "snprintf.h" -/* Get memcpy. */ +/* Get va_list, va_start, va_end. */ +#include +/* Get free. */ +#include +/* Get memcpy, size_t. */ #include /* Get vasnprintf. */ @@ -40,19 +44,24 @@ int snprintf (char *str, size_t size, const char *format, ...) { + char *output; size_t len; - char *out = vasnprintf (NULL, &len, format, args); + va_list args; - if (!out) + va_start (args, format); + output = vasnprintf (NULL, &len, format, args); + va_end (args); + + if (!output) return -1; if (str) { - memcpy (str, out, MIN (len + 1, size)); + memcpy (str, output, MIN (len + 1, size)); str[size - 1] = '\0'; } - free (out); + free (output); return len; } -- 2.30.2