]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/array.c
The KILL command killed much more than desired (including server links!)
[ngircd-alex.git] / src / ngircd / array.c
index 26c636a6394870d7d2aa941dbd7e46773c981cdb..bbff5a145c937fa125fd507a563890495662c43d 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "array.h"
 
-static char UNUSED id[] = "$Id: array.c,v 1.3 2005/07/11 14:10:53 fw Exp $";
+static char UNUSED id[] = "$Id: array.c,v 1.5 2005/07/28 16:12:50 fw Exp $";
 
 #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)
@@ -75,7 +85,7 @@ array_alloc(array * a, unsigned int size, unsigned int pos)
                        }
                }
 #ifdef DEBUG
-               Log(LOG_DEBUG, "Rounded %u to %u byte.", alloc, aligned);
+               Log(LOG_DEBUG, "array_alloc(): rounded %u to %u bytes.", alloc, aligned);
 #endif
 
                assert(aligned >= alloc);
@@ -85,7 +95,7 @@ array_alloc(array * a, unsigned int size, unsigned int pos)
 
                alloc = aligned;
 #ifdef DEBUG
-               Log(LOG_DEBUG, "array_alloc: changing size from %u to %u byte",
+               Log(LOG_DEBUG, "array_alloc(): changing size from %u to %u bytes.",
                    a->allocated, aligned);
 #endif
 
@@ -148,7 +158,7 @@ array_copyb(array * dest, const char *src, unsigned int len)
        memcpy(dest->mem, src, len);
 #ifdef DEBUG
        Log(LOG_DEBUG,
-           "array_copyb: copied %u bytes to array (%u total bytes allocated)",
+           "array_copyb(): copied %u bytes to array (%u bytes allocated).",
            len, dest->allocated);
 #endif
        return true;
@@ -196,7 +206,7 @@ array_catb(array * dest, const char *src, unsigned int len)
 
 #ifdef DEBUG
        Log(LOG_DEBUG,
-           "array_catb: appending %u bytes to array (now %u total bytes in array)",
+           "array_catb(): appending %u bytes to array (now %u bytes in array).",
            len, tmp);
 #endif
        memcpy(ptr + used, src, len);
@@ -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)
@@ -262,7 +284,7 @@ array_free(array * a)
        assert(a != NULL);
 #ifdef DEBUG
        Log(LOG_DEBUG,
-           "array_free: %u bytes free'd (%u bytes still used at time of free())",
+           "array_free(): %u bytes free'd (%u bytes still used at time of free()).",
            a->allocated, a->used);
 #endif
        free(a->mem);
@@ -333,7 +355,7 @@ array_moveleft(array * a, unsigned int membersize, unsigned int pos)
 
 #ifdef DEBUG
        Log(LOG_DEBUG,
-           "array_moveleft: %u used bytes in array, move to beginning, starting at pos %u",
+           "array_moveleft(): %u bytes used in array, starting at position %u.",
            a->used, bytepos);
 #endif
        if (a->used <= bytepos) {