Commit 11443ec7 authored by Jeremy Fitzhardinge's avatar Jeremy Fitzhardinge Committed by Linus Torvalds

Add kvasprintf()

Add a kvasprintf() function to complement kasprintf().

No in-tree users yet, but I have some coming up.

[akpm@linux-foundation.org: EXPORT it]
Signed-off-by: default avatarJeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Keir Fraser <keir@xensource.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9684e51c
...@@ -121,6 +121,7 @@ extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) ...@@ -121,6 +121,7 @@ extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
__attribute__ ((format (printf, 3, 0))); __attribute__ ((format (printf, 3, 0)));
extern char *kasprintf(gfp_t gfp, const char *fmt, ...) extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3))); __attribute__ ((format (printf, 2, 3)));
extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
extern int sscanf(const char *, const char *, ...) extern int sscanf(const char *, const char *, ...)
__attribute__ ((format (scanf, 2, 3))); __attribute__ ((format (scanf, 2, 3)));
......
...@@ -851,23 +851,35 @@ EXPORT_SYMBOL(sscanf); ...@@ -851,23 +851,35 @@ EXPORT_SYMBOL(sscanf);
/* Simplified asprintf. */ /* Simplified asprintf. */
char *kasprintf(gfp_t gfp, const char *fmt, ...) char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
{ {
va_list ap;
unsigned int len; unsigned int len;
char *p; char *p;
va_list aq;
va_start(ap, fmt); va_copy(aq, ap);
len = vsnprintf(NULL, 0, fmt, ap); len = vsnprintf(NULL, 0, fmt, aq);
va_end(ap); va_end(aq);
p = kmalloc(len+1, gfp); p = kmalloc(len+1, gfp);
if (!p) if (!p)
return NULL; return NULL;
va_start(ap, fmt);
vsnprintf(p, len+1, fmt, ap); vsnprintf(p, len+1, fmt, ap);
va_end(ap);
return p; return p;
} }
EXPORT_SYMBOL(kvasprintf);
char *kasprintf(gfp_t gfp, const char *fmt, ...)
{
va_list ap;
char *p;
va_start(ap, fmt);
p = kvasprintf(gfp, fmt, ap);
va_end(ap);
return p;
}
EXPORT_SYMBOL(kasprintf); EXPORT_SYMBOL(kasprintf);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment