#include "array.h"
-static char UNUSED id[] = "$Id: array.c,v 1.4 2005/07/14 09:14:12 alex Exp $";
+static char UNUSED id[] = "$Id: array.c,v 1.5 2005/07/28 16:12:50 fw Exp $";
#include <assert.h>
}
+void
+array_init(array *a)
+{
+ assert(a);
+ a->mem = NULL;
+ a->allocated = 0;
+ a->used = 0;
+}
+
+
/* if realloc() fails, array_alloc return NULL. otherwise return pointer to elem pos in array */
void *
array_alloc(array * a, unsigned int size, unsigned int pos)
}
+/* append trailing NUL byte to array, but do not count it. */
+bool
+array_cat0_temporary(array * a)
+{
+ unsigned int len = array_bytes(a);
+ if (!array_catb(a, "", 1))
+ return false;
+
+ array_truncate(a, 1, len);
+ return true;
+}
+
/* add contents of array src to array dest. */
bool
array_cat(array * dest, const array * const src)
* libarray - dynamically allocate arrays.
* Copyright (c) 2005 Florian Westphal (westphal@foo.fh-furtwangen.de)
*
- * $Id: array.h,v 1.2 2005/07/14 09:11:38 alex Exp $
+ * $Id: array.h,v 1.3 2005/07/28 16:12:50 fw Exp $
*/
#ifndef array_h_included
#define array_unallocated(x) (array_bytes(x)==0)
#define INIT_ARRAY { NULL, 0, 0 }
+/* set all variables in a to 0 */
+extern void array_init PARAMS((array *a));
+
/* allocates space for at least nmemb+1 elements of size bytes each.
return pointer to elem at pos, or NULL if realloc() fails */
extern void * array_alloc PARAMS((array *a, unsigned int size, unsigned int pos));
/* append NUL byte to dest */
extern bool array_cat0 PARAMS((array* dest));
+/* append NUL byte to dest, but do not count null byte */
+extern bool array_cat0_temporary PARAMS((array* dest));
+
/* append contents of array src to array dest. */
extern bool array_cat PARAMS((array* dest, const array* const src));