klibc-bot for H. Peter Anvin
2016-Feb-01 09:57 UTC
[klibc] [klibc:master] Make asprintf() a simple wrapper around vasprintf()
Commit-ID: 17fabd540aeb5019909a024243c6d26610cab307 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=17fabd540aeb5019909a024243c6d26610cab307 Author: H. Peter Anvin <hpa at zytor.com> AuthorDate: Mon, 1 Feb 2016 01:55:04 -0800 Committer: H. Peter Anvin <hpa at zytor.com> CommitDate: Mon, 1 Feb 2016 01:55:04 -0800 [klibc] Make asprintf() a simple wrapper around vasprintf() Since we have vasprintf() anyway, save about a hundred bytes (on x86-64) by making asprintf() a typical stdarg wrapper function. Signed-off-by: H. Peter Anvin <hpa at zytor.com> --- usr/klibc/asprintf.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/usr/klibc/asprintf.c b/usr/klibc/asprintf.c index a3f5f00..ce3aa76 100644 --- a/usr/klibc/asprintf.c +++ b/usr/klibc/asprintf.c @@ -8,22 +8,13 @@ int asprintf(char **bufp, const char *format, ...) { - va_list ap, ap1; + va_list ap; int rv; int bytes; char *p; va_start(ap, format); - va_copy(ap1, ap); - - bytes = vsnprintf(NULL, 0, format, ap1) + 1; - va_end(ap1); - - *bufp = p = malloc(bytes); - if (!p) - return -1; - - rv = vsnprintf(p, bytes, format, ap); + rv = vasprintf(bufp, format, ap); va_end(ap); return rv;