diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-11 16:52:10 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-15 12:21:45 +0200 |
commit | 947fb5adf8af450507c978abf1c7ec9f051e5842 (patch) | |
tree | af790669292308b56baf188611ac430012037cba /lib | |
parent | 48b205e32342fc8a2648b2bd3f1f6d9a7d74e6cb (diff) | |
download | barebox-947fb5adf8af450507c978abf1c7ec9f051e5842.tar.gz barebox-947fb5adf8af450507c978abf1c7ec9f051e5842.tar.xz |
string: Fix (v)asprintf prototypes
Our asprintf and vasprintf have different prototypes than the glibc
functions. This causes trouble when we want to share barebox code
with userspace code. Change the prototypes for (v)asprintf to match
the glibc prototypes. Since the current (v)asprintf are convenient
to use change the existing functions to b(v)asprintf.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libfile.c | 6 | ||||
-rw-r--r-- | lib/logo/logo.c | 2 | ||||
-rw-r--r-- | lib/parameter.c | 8 | ||||
-rw-r--r-- | lib/stringlist.c | 2 | ||||
-rw-r--r-- | lib/uncompress.c | 3 | ||||
-rw-r--r-- | lib/vsprintf.c | 48 | ||||
-rw-r--r-- | lib/xfuncs.c | 2 |
7 files changed, 52 insertions, 19 deletions
diff --git a/lib/libfile.c b/lib/libfile.c index 2c72ffe066..62e9b8ed22 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -91,7 +91,7 @@ char *read_file_line(const char *fmt, ...) struct stat s; va_start(args, fmt); - filename = vasprintf(fmt, args); + filename = bvasprintf(fmt, args); va_end(args); ret = stat(filename, &s); @@ -359,8 +359,8 @@ int copy_recursive(const char *src, const char *dst) if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue; - from = asprintf("%s/%s", src, d->d_name); - to = asprintf("%s/%s", dst, d->d_name); + from = basprintf("%s/%s", src, d->d_name); + to = basprintf("%s/%s", dst, d->d_name); ret = copy_recursive(from, to); if (ret) break; diff --git a/lib/logo/logo.c b/lib/logo/logo.c index 614d8c0908..9edf212232 100644 --- a/lib/logo/logo.c +++ b/lib/logo/logo.c @@ -36,7 +36,7 @@ static void load_logo(int width, void *start, void *end) char *filename; size_t size = end - start; - filename = asprintf("/logo/barebox-logo-%d.png", width); + filename = basprintf("/logo/barebox-logo-%d.png", width); write_file(filename, start, size); free(filename); } diff --git a/lib/parameter.c b/lib/parameter.c index fd05b49adf..ba6b5daead 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -341,7 +341,7 @@ static const char *param_int_get(struct device_d *dev, struct param_d *p) } free(p->value); - p->value = asprintf(pi->format, *pi->value); + p->value = basprintf(pi->format, *pi->value); return p->value; } @@ -443,7 +443,7 @@ static const char *param_enum_get(struct device_d *dev, struct param_d *p) free(p->value); if (*pe->value >= pe->num_names) - p->value = asprintf("invalid:%d", *pe->value); + p->value = basprintf("invalid:%d", *pe->value); else p->value = strdup(pe->names[*pe->value]); @@ -556,7 +556,7 @@ struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name, return ERR_PTR(ret); } - piro->param.value = asprintf(format, value); + piro->param.value = basprintf(format, value); return &piro->param; } @@ -582,7 +582,7 @@ struct param_d *dev_add_param_llint_ro(struct device_d *dev, const char *name, return ERR_PTR(ret); } - piro->param.value = asprintf(format, value); + piro->param.value = basprintf(format, value); return &piro->param; } diff --git a/lib/stringlist.c b/lib/stringlist.c index 8a18366a96..8e92c1b207 100644 --- a/lib/stringlist.c +++ b/lib/stringlist.c @@ -34,7 +34,7 @@ int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...) va_start(args, fmt); - new->str = vasprintf(fmt, args); + new->str = bvasprintf(fmt, args); va_end(args); diff --git a/lib/uncompress.c b/lib/uncompress.c index 329c9fc366..3e4bc5f9e5 100644 --- a/lib/uncompress.c +++ b/lib/uncompress.c @@ -125,7 +125,8 @@ int uncompress(unsigned char *inbuf, int len, break; #endif default: - err = asprintf("cannot handle filetype %s", file_type_to_string(ft)); + err = basprintf("cannot handle filetype %s", + file_type_to_string(ft)); error_fn(err); free(err); ret = -ENOSYS; diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 00b8863957..1122a4ad38 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -646,12 +646,11 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...) } EXPORT_SYMBOL(scnprintf); -/* Simplified asprintf. */ -char *vasprintf(const char *fmt, va_list ap) +int vasprintf(char **strp, const char *fmt, va_list ap) { unsigned int len; - char *p; va_list aq; + char *p; va_copy(aq, ap); len = vsnprintf(NULL, 0, fmt, aq); @@ -659,23 +658,56 @@ char *vasprintf(const char *fmt, va_list ap) p = malloc(len + 1); if (!p) - return NULL; + return -1; vsnprintf(p, len + 1, fmt, ap); - return p; + *strp = p; + + return len; } EXPORT_SYMBOL(vasprintf); -char *asprintf(const char *fmt, ...) +char *bvasprintf(const char *fmt, va_list ap) +{ + char *p; + int len; + + len = vasprintf(&p, fmt, ap); + if (len < 0) + return NULL; + + return p; +} +EXPORT_SYMBOL(bvasprintf); + +int asprintf(char **strp, const char *fmt, ...) { va_list ap; char *p; + int len; va_start(ap, fmt); - p = vasprintf(fmt, ap); + len = vasprintf(&p, fmt, ap); va_end(ap); - return p; + return len; } EXPORT_SYMBOL(asprintf); + +char *basprintf(const char *fmt, ...) +{ + va_list ap; + char *p; + int len; + + va_start(ap, fmt); + len = vasprintf(&p, fmt, ap); + va_end(ap); + + if (len < 0) + return NULL; + + return p; +} +EXPORT_SYMBOL(basprintf); diff --git a/lib/xfuncs.c b/lib/xfuncs.c index 152081c662..aaf0788544 100644 --- a/lib/xfuncs.c +++ b/lib/xfuncs.c @@ -109,7 +109,7 @@ char *xvasprintf(const char *fmt, va_list ap) { char *p; - p = vasprintf(fmt, ap); + p = bvasprintf(fmt, ap); if (!p) panic("ERROR: out of memory\n"); return p; |