changeset 5290:a32d2a4a925f

Fixes, mostly from Simon Josefsson.
author Bruno Haible <bruno@clisp.org>
date Fri, 01 Oct 2004 10:26:52 +0000
parents dbb03bb624ad
children 2b9cda789a2d
files lib/ChangeLog lib/snprintf.c
diffstat 2 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,6 +1,8 @@
-2004-10-01  Bruno Haible  <bruno@clisp.org>
-
-	* snprintf.c: Include <string.h>.
+2004-10-01  Simon Josefsson  <jas@extundo.com>
+            Bruno Haible  <bruno@clisp.org>
+
+	* snprintf.c: Include <stdarg.h>, <stdlib.h>, <string.h>.
+	(snprintf): Declare 'args'.
 
 2004-09-30  Simon Josefsson  <jas@extundo.com>
 
--- a/lib/snprintf.c
+++ b/lib/snprintf.c
@@ -20,10 +20,14 @@
 # include <config.h>
 #endif
 
-/* Get specification.  */
+/* Specification.  */
 #include "snprintf.h"
 
-/* Get memcpy.  */
+/* Get va_list, va_start, va_end. */
+#include <stdarg.h>
+/* Get free. */
+#include <stdlib.h>
+/* Get memcpy, size_t. */
 #include <string.h>
 
 /* 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;
 }