]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/array.h
New configuration option "NoZeroConf" to disable ZeroConf registration
[ngircd-alex.git] / src / ngircd / array.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  * Please read the file COPYING, README and AUTHORS for more information.
7  *
8  * libarray - dynamically allocate arrays.
9  * Copyright (c) 2005 Florian Westphal (westphal@foo.fh-furtwangen.de)
10  *
11  * $Id: array.h,v 1.4 2005/08/30 13:36:32 fw Exp $
12  */
13
14 #ifndef array_h_included
15 #define array_h_included
16
17 #include "portab.h"
18
19 typedef struct {
20         char * mem;
21         size_t allocated;
22         size_t used;
23 } array;
24
25 /* allocated: mem != NULL, used >= 0 && used <= allocated, allocated > 0
26    unallocated: mem == NULL, allocated == 0, used == 0 */
27
28 #define array_unallocated(x)    (array_bytes(x)==0)
29 #define INIT_ARRAY              { NULL, 0, 0 }
30
31 /* set all variables in a to 0 */
32 extern void array_init PARAMS((array *a));
33
34 /* allocates space for at least nmemb+1 elements of size bytes each.
35    return pointer to elem at pos, or NULL if realloc() fails */
36 extern void * array_alloc PARAMS((array *a, size_t size, size_t pos));
37
38 /* returns the number of initialized BYTES in a. */
39 #define array_bytes(array)      ( (array)->used )
40
41 /* returns the number of initialized ELEMS in a. */
42 extern size_t array_length PARAMS((const array* const a, size_t elemsize));
43
44 /* _copy functions: copy src to dest.
45    return true if OK, else false (e. g. realloc failure, invalid src/dest
46    array, ...). In that case dest is left unchanged. */
47
48 /* copy array src to dest */
49 extern bool array_copy PARAMS((array* dest, const array* const src));
50
51 /* copy len bytes from src to array dest. */
52 extern bool array_copyb PARAMS((array* dest, const char* src, size_t len));
53
54 /* copy string to dest */
55 extern bool array_copys PARAMS((array* dest, const char* src));
56
57 /* _cat functions: append src to dest.
58    return true if OK, else false (e. g. realloc failure, invalid src/dest
59    array, ...). In that case dest is left unchanged. */
60
61 /* append len bytes from src to array dest. */
62 extern bool array_catb PARAMS((array* dest, const char* src, size_t len));
63
64 /* append string to dest */
65 extern bool array_cats PARAMS((array* dest, const char* src));
66
67 /* append NUL byte to dest */
68 extern bool array_cat0 PARAMS((array* dest));
69
70 /* append NUL byte to dest, but do not count null byte */
71 extern bool array_cat0_temporary PARAMS((array* dest));
72
73 /* append contents of array src to array dest. */
74 extern bool array_cat PARAMS((array* dest, const array* const src));
75
76 /* return pointer to element at pos.
77    return NULL if the array is unallocated or if pos is larger than the number
78    of elements stored int the array. */
79 extern void* array_get PARAMS((array* a, size_t membersize, size_t pos));
80
81 /* free the contents of this array. */
82 extern void array_free PARAMS((array* a));
83
84 /* overwrite array with zeroes before free */
85 extern void array_free_wipe PARAMS((array* a));
86
87 /* return pointer to first element in this array */
88 extern void* array_start PARAMS((const array* const a));
89
90 /* reset this array (the memory is not free'd */
91 extern void array_trunc PARAMS((array* a));
92
93 /* set number of used elements in this array to len */
94 extern void array_truncate PARAMS((array* a, size_t membersize, size_t len));
95
96 /* move elements starting at pos to beginning of array */
97 extern void array_moveleft PARAMS((array* a, size_t membersize, size_t pos));
98
99 #endif
100
101 /* -eof- */