1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-01-18 19:42:50 +00:00

add array_cat0_temporary() and array_init()

This commit is contained in:
Florian Westphal 2005-07-28 16:12:50 +00:00
parent 21a067e0b1
commit 20ff63a8a1
2 changed files with 30 additions and 2 deletions

View File

@ -12,7 +12,7 @@
#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>
@ -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)
@ -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)

View File

@ -8,7 +8,7 @@
* 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
@ -28,6 +28,9 @@ typedef struct {
#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));
@ -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, 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));