summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8a37537)
raw | patch | inline | side by side (parent: 8a37537)
author | Florian Forster <ff@octo.it> | |
Fri, 2 Jul 2010 17:31:37 +0000 (19:31 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 2 Jul 2010 17:31:37 +0000 (19:31 +0200) |
src/utils_array.c | patch | blob | history | |
src/utils_array.h | patch | blob | history |
diff --git a/src/utils_array.c b/src/utils_array.c
index e7ac51e784fe9aaa5def1b5fac5fe2c6e0dd70fc..93e3568d716e686d1eabeed70764f85bc1f7ffbe 100644 (file)
--- a/src/utils_array.c
+++ b/src/utils_array.c
return (array_append (a, buffer));
} /* }}} int array_append_format */
+int array_prepend (str_array_t *a, const char *entry) /* {{{ */
+{
+ char **ptr;
+ char *cpy;
+
+ if ((entry == NULL) || (a == NULL))
+ return (EINVAL);
+
+ cpy = strdup (entry);
+ if (cpy == NULL)
+ return (ENOMEM);
+
+ ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
+ if (ptr == NULL)
+ {
+ free (cpy);
+ return (ENOMEM);
+ }
+ a->ptr = ptr;
+
+ memmove (a->ptr, a->ptr + 1, sizeof (*a->ptr) * a->size);
+ a->ptr[0] = cpy;
+ a->size++;
+
+ return (0);
+} /* }}} int array_prepend */
+
+int array_prepend_format (str_array_t *a, const char *format, ...) /* {{{ */
+{
+ char buffer[1024];
+ va_list ap;
+ int status;
+
+ va_start (ap, format);
+ status = vsnprintf (buffer, sizeof (buffer), format, ap);
+ va_end(ap);
+
+ if ((status < 0) || (((size_t) status) >= sizeof (buffer)))
+ return (ENOMEM);
+
+ return (array_prepend (a, buffer));
+} /* }}} int array_prepend_format */
+
int array_sort (str_array_t *a) /* {{{ */
{
if (a == NULL)
diff --git a/src/utils_array.h b/src/utils_array.h
index 141dbaa48fdd2ca432cb5ee0459c05c09e61a0c5..53670c5abdd16bec0a6e884acadf66ff1e937065 100644 (file)
--- a/src/utils_array.h
+++ b/src/utils_array.h
str_array_t *array_create (void);
void array_destroy (str_array_t *a);
+
int array_append (str_array_t *a, const char *entry);
int array_append_format (str_array_t *a, const char *format, ...)
__attribute__((format(printf,2,3)));
+int array_prepend (str_array_t *a, const char *entry);
+int array_prepend_format (str_array_t *a, const char *format, ...)
+ __attribute__((format(printf,2,3)));
+
int array_sort (str_array_t *a);
int array_argc (str_array_t *);