diff options
author | Jeremy Fitzhardinge <jeremy@goop.org> | 2007-04-30 18:09:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-04-30 19:40:40 -0400 |
commit | 11443ec7d9286dd25663516436a14edfb5f43857 (patch) | |
tree | 121137dbd7b323cd5dce71cbb8da8119a642b731 | |
parent | 9684e51cd157607f0727c1550e7df6e31de40808 (diff) |
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: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Keir Fraser <keir@xensource.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/kernel.h | 1 | ||||
-rw-r--r-- | lib/vsprintf.c | 26 |
2 files changed, 20 insertions, 7 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 9ddf25c21538..e2f41b051b12 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -121,6 +121,7 @@ extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
121 | __attribute__ ((format (printf, 3, 0))); | 121 | __attribute__ ((format (printf, 3, 0))); |
122 | extern char *kasprintf(gfp_t gfp, const char *fmt, ...) | 122 | extern char *kasprintf(gfp_t gfp, const char *fmt, ...) |
123 | __attribute__ ((format (printf, 2, 3))); | 123 | __attribute__ ((format (printf, 2, 3))); |
124 | extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); | ||
124 | 125 | ||
125 | extern int sscanf(const char *, const char *, ...) | 126 | extern int sscanf(const char *, const char *, ...) |
126 | __attribute__ ((format (scanf, 2, 3))); | 127 | __attribute__ ((format (scanf, 2, 3))); |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index b025864d2e43..cbab1df150cf 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -851,23 +851,35 @@ EXPORT_SYMBOL(sscanf); | |||
851 | 851 | ||
852 | 852 | ||
853 | /* Simplified asprintf. */ | 853 | /* Simplified asprintf. */ |
854 | char *kasprintf(gfp_t gfp, const char *fmt, ...) | 854 | char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap) |
855 | { | 855 | { |
856 | va_list ap; | ||
857 | unsigned int len; | 856 | unsigned int len; |
858 | char *p; | 857 | char *p; |
858 | va_list aq; | ||
859 | 859 | ||
860 | va_start(ap, fmt); | 860 | va_copy(aq, ap); |
861 | len = vsnprintf(NULL, 0, fmt, ap); | 861 | len = vsnprintf(NULL, 0, fmt, aq); |
862 | va_end(ap); | 862 | va_end(aq); |
863 | 863 | ||
864 | p = kmalloc(len+1, gfp); | 864 | p = kmalloc(len+1, gfp); |
865 | if (!p) | 865 | if (!p) |
866 | return NULL; | 866 | return NULL; |
867 | va_start(ap, fmt); | 867 | |
868 | vsnprintf(p, len+1, fmt, ap); | 868 | vsnprintf(p, len+1, fmt, ap); |
869 | va_end(ap); | 869 | |
870 | return p; | 870 | return p; |
871 | } | 871 | } |
872 | EXPORT_SYMBOL(kvasprintf); | ||
873 | |||
874 | char *kasprintf(gfp_t gfp, const char *fmt, ...) | ||
875 | { | ||
876 | va_list ap; | ||
877 | char *p; | ||
872 | 878 | ||
879 | va_start(ap, fmt); | ||
880 | p = kvasprintf(gfp, fmt, ap); | ||
881 | va_end(ap); | ||
882 | |||
883 | return p; | ||
884 | } | ||
873 | EXPORT_SYMBOL(kasprintf); | 885 | EXPORT_SYMBOL(kasprintf); |