aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2007-04-30 18:09:56 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-04-30 19:40:40 -0400
commit11443ec7d9286dd25663516436a14edfb5f43857 (patch)
tree121137dbd7b323cd5dce71cbb8da8119a642b731 /lib
parent9684e51cd157607f0727c1550e7df6e31de40808 (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>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c26
1 files changed, 19 insertions, 7 deletions
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. */
854char *kasprintf(gfp_t gfp, const char *fmt, ...) 854char *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}
872EXPORT_SYMBOL(kvasprintf);
873
874char *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}
873EXPORT_SYMBOL(kasprintf); 885EXPORT_SYMBOL(kasprintf);