7 #include "utils_array.h"
15 str_array_t *array_create (void) /* {{{ */
19 a = malloc (sizeof (*a));
23 memset (a, 0, sizeof (*a));
28 } /* }}} str_array_t *array_create */
30 void array_destroy (str_array_t *a) /* {{{ */
40 } /* }}} void array_destroy */
42 int array_append (str_array_t *a, const char *entry) /* {{{ */
46 if ((entry == NULL) || (a == NULL))
49 ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
53 ptr = a->ptr + a->size;
55 *ptr = strdup (entry);
61 } /* }}} int array_append */
63 int array_append_format (str_array_t *a, const char *format, ...) /* {{{ */
69 va_start (ap, format);
70 status = vsnprintf (buffer, sizeof (buffer), format, ap);
73 if ((status < 0) || (((size_t) status) >= sizeof (buffer)))
76 return (array_append (a, buffer));
77 } /* }}} int array_append_format */
79 int array_argc (str_array_t *a) /* {{{ */
84 return ((int) a->size);
85 } /* }}} int array_argc */
87 char **array_argv (str_array_t *a) /* {{{ */
89 if ((a == NULL) || (a->size == 0))
93 } /* }}} char **array_argv */
95 /* vim: set sw=2 sts=2 et fdm=marker : */