Skip to content

Commit

Permalink
Add kvasprintf()
Browse files Browse the repository at this point in the history
Add a kvasprintf() function to complement kasprintf().

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

[[email protected]: EXPORT it]
Signed-off-by: Jeremy Fitzhardinge <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Keir Fraser <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jsgf authored and Linus Torvalds committed Apr 30, 2007
1 parent 9684e51 commit 11443ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
__attribute__ ((format (printf, 3, 0)));
extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);

extern int sscanf(const char *, const char *, ...)
__attribute__ ((format (scanf, 2, 3)));
Expand Down
26 changes: 19 additions & 7 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,23 +851,35 @@ EXPORT_SYMBOL(sscanf);


/* 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;
char *p;
va_list aq;

va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
va_copy(aq, ap);
len = vsnprintf(NULL, 0, fmt, aq);
va_end(aq);

p = kmalloc(len+1, gfp);
if (!p)
return NULL;
va_start(ap, fmt);

vsnprintf(p, len+1, fmt, ap);
va_end(ap);

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);

0 comments on commit 11443ec

Please sign in to comment.