diff options
-rw-r--r-- | include/linux/kernel.h | 2 | ||||
-rw-r--r-- | lib/vsprintf.c | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 8c21aaa248b4..3c5e4c2e517d 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -117,6 +117,8 @@ extern int scnprintf(char * buf, size_t size, const char * fmt, ...) | |||
117 | __attribute__ ((format (printf, 3, 4))); | 117 | __attribute__ ((format (printf, 3, 4))); |
118 | extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | 118 | extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) |
119 | __attribute__ ((format (printf, 3, 0))); | 119 | __attribute__ ((format (printf, 3, 0))); |
120 | extern char *kasprintf(gfp_t gfp, const char *fmt, ...) | ||
121 | __attribute__ ((format (printf, 2, 3))); | ||
120 | 122 | ||
121 | extern int sscanf(const char *, const char *, ...) | 123 | extern int sscanf(const char *, const char *, ...) |
122 | __attribute__ ((format (scanf, 2, 3))); | 124 | __attribute__ ((format (scanf, 2, 3))); |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index f5959476e53d..797428afd111 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -849,3 +849,26 @@ int sscanf(const char * buf, const char * fmt, ...) | |||
849 | } | 849 | } |
850 | 850 | ||
851 | EXPORT_SYMBOL(sscanf); | 851 | EXPORT_SYMBOL(sscanf); |
852 | |||
853 | |||
854 | /* Simplified asprintf. */ | ||
855 | char *kasprintf(gfp_t gfp, const char *fmt, ...) | ||
856 | { | ||
857 | va_list ap; | ||
858 | unsigned int len; | ||
859 | char *p; | ||
860 | |||
861 | va_start(ap, fmt); | ||
862 | len = vsnprintf(NULL, 0, fmt, ap); | ||
863 | va_end(ap); | ||
864 | |||
865 | p = kmalloc(len+1, gfp); | ||
866 | if (!p) | ||
867 | return NULL; | ||
868 | va_start(ap, fmt); | ||
869 | vsnprintf(p, len+1, fmt, ap); | ||
870 | va_end(ap); | ||
871 | return p; | ||
872 | } | ||
873 | |||
874 | EXPORT_SYMBOL(kasprintf); | ||