diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-05-01 21:41:59 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-05-01 21:41:59 +0200 |
commit | e4e3fbd22bca38f10f1cd7a3f5eb75e0b265dcaa (patch) | |
tree | fc713ed2e9b4ed774bc4dda9521dcb7ff867e2dd /lib | |
parent | 8ca42643d4a3a15d4802f93d1433e640b846df04 (diff) | |
parent | 9492976bc88a9fe4633202681fcdc24ce1dab636 (diff) | |
download | barebox-e4e3fbd22bca38f10f1cd7a3f5eb75e0b265dcaa.tar.gz barebox-e4e3fbd22bca38f10f1cd7a3f5eb75e0b265dcaa.tar.xz |
Merge tag 'complete_update_support' of git://git.jcrosoft.org/barebox into next
improve complete support
The following patch serie improve the complete support
by adding a complete framework to allow commands complete support.
The add also car complete support for eval and setting and executable
file support
This also include an update of the stringlist API to support asprintf
API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stringlist.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/stringlist.c b/lib/stringlist.c index a8ff97964f..b965aa058c 100644 --- a/lib/stringlist.c +++ b/lib/stringlist.c @@ -1,6 +1,7 @@ #include <common.h> #include <xfuncs.h> #include <malloc.h> +#include <errno.h> #include <stringlist.h> static int string_list_compare(struct list_head *a, struct list_head *b) @@ -16,9 +17,31 @@ int string_list_add(struct string_list *sl, char *str) { struct string_list *new; - new = xmalloc(sizeof(struct string_list) + strlen(str) + 1); + new = xmalloc(sizeof(*new)); + new->str = xstrdup(str); - strcpy(new->str, str); + list_add_tail(&new->list, &sl->list); + + return 0; +} + +int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...) +{ + struct string_list *new; + va_list args; + + new = xmalloc(sizeof(*new)); + + va_start(args, fmt); + + new->str = vasprintf(fmt, args); + + va_end(args); + + if (!new->str) { + free(new); + return -ENOMEM; + } list_add_tail(&new->list, &sl->list); @@ -29,9 +52,8 @@ int string_list_add_sorted(struct string_list *sl, char *str) { struct string_list *new; - new = xmalloc(sizeof(struct string_list) + strlen(str) + 1); - - strcpy(new->str, str); + new = xmalloc(sizeof(*new)); + new->str = xstrdup(str); list_add_sort(&new->list, &sl->list, string_list_compare); |