diff options
author | Jeremy Fitzhardinge <jeremy@xensource.com> | 2006-06-25 08:49:17 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-25 13:01:23 -0400 |
commit | e905914f96e11862b130dd229f73045dad9a34e8 (patch) | |
tree | 0e7cff381970e2439de521c3d42ded8c49f69354 /lib | |
parent | f796937a062c7aeb44cd0e75e1586c8543634a7d (diff) |
[PATCH] Implement kasprintf
Implement kasprintf, a kernel version of asprintf. This allocates the
memory required for the formatted string, including the trailing '\0'.
Returns NULL on allocation failure.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 23 |
1 files changed, 23 insertions, 0 deletions
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); | ||