aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b025864d2e43..017290241261 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -825,6 +825,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
825 break; 825 break;
826 str = next; 826 str = next;
827 } 827 }
828
829 /*
830 * Now we've come all the way through so either the input string or the
831 * format ended. In the former case, there can be a %n at the current
832 * position in the format that needs to be filled.
833 */
834 if (*fmt == '%' && *(fmt + 1) == 'n') {
835 int *p = (int *)va_arg(args, int *);
836 *p = str - buf;
837 }
838
828 return num; 839 return num;
829} 840}
830 841
@@ -851,23 +862,35 @@ EXPORT_SYMBOL(sscanf);
851 862
852 863
853/* Simplified asprintf. */ 864/* Simplified asprintf. */
854char *kasprintf(gfp_t gfp, const char *fmt, ...) 865char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
855{ 866{
856 va_list ap;
857 unsigned int len; 867 unsigned int len;
858 char *p; 868 char *p;
869 va_list aq;
859 870
860 va_start(ap, fmt); 871 va_copy(aq, ap);
861 len = vsnprintf(NULL, 0, fmt, ap); 872 len = vsnprintf(NULL, 0, fmt, aq);
862 va_end(ap); 873 va_end(aq);
863 874
864 p = kmalloc(len+1, gfp); 875 p = kmalloc(len+1, gfp);
865 if (!p) 876 if (!p)
866 return NULL; 877 return NULL;
867 va_start(ap, fmt); 878
868 vsnprintf(p, len+1, fmt, ap); 879 vsnprintf(p, len+1, fmt, ap);
869 va_end(ap); 880
870 return p; 881 return p;
871} 882}
883EXPORT_SYMBOL(kvasprintf);
872 884
885char *kasprintf(gfp_t gfp, const char *fmt, ...)
886{
887 va_list ap;
888 char *p;
889
890 va_start(ap, fmt);
891 p = kvasprintf(gfp, fmt, ap);
892 va_end(ap);
893
894 return p;
895}
873EXPORT_SYMBOL(kasprintf); 896EXPORT_SYMBOL(kasprintf);