]> arthur.barton.de Git - ngircd-alex.git/commitdiff
add array_cat0_temporary() and array_init()
authorFlorian Westphal <fw@strlen.de>
Thu, 28 Jul 2005 16:12:50 +0000 (16:12 +0000)
committerFlorian Westphal <fw@strlen.de>
Thu, 28 Jul 2005 16:12:50 +0000 (16:12 +0000)
src/ngircd/array.c
src/ngircd/array.h

index f45c0a3aecd29a3d1d6f1471f84488866b55b70a..bbff5a145c937fa125fd507a563890495662c43d 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "array.h"
 
 
 #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>
 
 
 #include <assert.h>
 
@@ -48,6 +48,16 @@ safemult_uint(unsigned int a, unsigned int b, unsigned int *res)
 }
 
 
 }
 
 
+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)
 /* 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)
@@ -221,6 +231,18 @@ array_cat0(array * a)
 }
 
 
 }
 
 
+/* 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)
 /* add contents of array src to array dest. */
 bool
 array_cat(array * dest, const array * const src)
index 82ea2f0d78bc9f528d16f924fbcdcf424a56dd49..236724c545cd277ff77c2a6be50c99f8d27c4c79 100644 (file)
@@ -8,7 +8,7 @@
  * libarray - dynamically allocate arrays.
  * Copyright (c) 2005 Florian Westphal (westphal@foo.fh-furtwangen.de)
  *
  * 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
  */
 
 #ifndef array_h_included
@@ -28,6 +28,9 @@ typedef struct {
 #define array_unallocated(x)   (array_bytes(x)==0)
 #define INIT_ARRAY             { NULL, 0, 0 }
 
 #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));
 /* 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));
@@ -64,6 +67,9 @@ extern bool array_cats PARAMS((array* dest, const char* src));
 /* append NUL byte to dest */
 extern bool array_cat0 PARAMS((array* dest));
 
 /* 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));
 
 /* append contents of array src to array dest. */
 extern bool array_cat PARAMS((array* dest, const array* const src));