Get rid of capacity argument to ds_init() and update all callers.
[pspp-builds.git] / src / libpspp / str.c
index c4ce9c512b74a94a919dc06aff46d9983b5b5c38..ef2be7d068479ee023b484386a9d53d537d30407 100644 (file)
    02110-1301, USA. */
 
 #include <config.h>
+
 #include "str.h"
-#include "message.h"
+
 #include <ctype.h>
 #include <limits.h>
 #include <stdlib.h>
-#include "alloc.h"
-#include "message.h"
+
+#include <libpspp/alloc.h>
+#include <libpspp/message.h>
+
 #include "minmax.h"
 #include "size_max.h"
 \f
@@ -244,13 +247,13 @@ ds_create (struct string *st, const char *s)
   strcpy (st->string, s);
 }
 
-/* Initializes ST, making room for at least CAPACITY characters. */
+/* Initializes ST as an empty string. */
 void
-ds_init (struct string *st, size_t capacity)
+ds_init (struct string *st)
 {
   st->length = 0;
-  st->capacity = MAX (8, capacity);
-  st->string = xmalloc (st->capacity + 1);
+  st->capacity = 0;
+  st->string = NULL;
 }
 
 /* Frees ST. */
@@ -282,7 +285,7 @@ ds_init_substring (struct string *dst,
                    const struct string *src, size_t idx, size_t cnt)
 {
   assert (dst != src);
-  ds_init (dst, cnt);
+  ds_init (dst);
   ds_assign_substring (dst, src, idx, cnt);
 }
 
@@ -714,10 +717,6 @@ ds_vprintf (struct string *st, const char *format, va_list args_)
   int avail, needed;
   va_list args;
 
-#ifndef va_copy
-#define va_copy(DST, SRC) (DST) = (SRC)
-#endif
-
   va_copy (args, args_);
   avail = st->string != NULL ? st->capacity - st->length + 1 : 0;
   needed = vsnprintf (st->string + st->length, avail, format, args);