7 #include "utils_array.h"
15 static int sort_callback (const void *v0, const void *v1) /* {{{ */
20 return (strcmp (c0, c1));
21 } /* }}} int sort_callback */
23 str_array_t *array_create (void) /* {{{ */
27 a = malloc (sizeof (*a));
31 memset (a, 0, sizeof (*a));
36 } /* }}} str_array_t *array_create */
38 void array_destroy (str_array_t *a) /* {{{ */
48 } /* }}} void array_destroy */
50 int array_append (str_array_t *a, const char *entry) /* {{{ */
54 if ((entry == NULL) || (a == NULL))
57 ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
61 ptr = a->ptr + a->size;
63 *ptr = strdup (entry);
69 } /* }}} int array_append */
71 int array_append_format (str_array_t *a, const char *format, ...) /* {{{ */
77 va_start (ap, format);
78 status = vsnprintf (buffer, sizeof (buffer), format, ap);
81 if ((status < 0) || (((size_t) status) >= sizeof (buffer)))
84 return (array_append (a, buffer));
85 } /* }}} int array_append_format */
87 int array_sort (str_array_t *a) /* {{{ */
92 qsort (a->ptr, a->size, sizeof (*a->ptr), sort_callback);
95 } /* }}} int array_sort */
97 int array_argc (str_array_t *a) /* {{{ */
102 return ((int) a->size);
103 } /* }}} int array_argc */
105 char **array_argv (str_array_t *a) /* {{{ */
107 if ((a == NULL) || (a->size == 0))
111 } /* }}} char **array_argv */
113 /* vim: set sw=2 sts=2 et fdm=marker : */