Fixes, mostly from Simon Josefsson.
authorBruno Haible <bruno@clisp.org>
Fri, 1 Oct 2004 10:26:52 +0000 (10:26 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 1 Oct 2004 10:26:52 +0000 (10:26 +0000)
lib/ChangeLog
lib/snprintf.c

index f92f908..a701b15 100644 (file)
@@ -1,6 +1,8 @@
-2004-10-01  Bruno Haible  <bruno@clisp.org>
+2004-10-01  Simon Josefsson  <jas@extundo.com>
+            Bruno Haible  <bruno@clisp.org>
 
-       * snprintf.c: Include <string.h>.
+       * snprintf.c: Include <stdarg.h>, <stdlib.h>, <string.h>.
+       (snprintf): Declare 'args'.
 
 2004-09-30  Simon Josefsson  <jas@extundo.com>
 
index 417dd33..92c2652 100644 (file)
 # 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.  */
 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;
 }