]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - lib/vsprintf.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
7 /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
9 * Wirzenius wrote this portably, Torvalds fucked it up :-)
13 * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com>
14 * - changed to provide snprintf and vsnprintf functions
15 * So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de>
16 * - scnprintf and vscnprintf
20 #include <linux/module.h>
21 #include <linux/types.h>
22 #include <linux/string.h>
23 #include <linux/ctype.h>
24 #include <linux/kernel.h>
25 #include <linux/kallsyms.h>
26 #include <linux/uaccess.h>
27 #include <linux/ioport.h>
29 #include <asm/page.h> /* for PAGE_SIZE */
30 #include <asm/div64.h>
31 #include <asm/sections.h> /* for dereference_function_descriptor() */
33 /* Works only for digits and letters, but small and fast */
34 #define TOLOWER(x) ((x) | 0x20)
36 static unsigned int simple_guess_base(const char *cp
)
39 if (TOLOWER(cp
[1]) == 'x' && isxdigit(cp
[2]))
49 * simple_strtoul - convert a string to an unsigned long
50 * @cp: The start of the string
51 * @endp: A pointer to the end of the parsed string will be placed here
52 * @base: The number base to use
54 unsigned long simple_strtoul(const char *cp
, char **endp
, unsigned int base
)
56 unsigned long result
= 0;
59 base
= simple_guess_base(cp
);
61 if (base
== 16 && cp
[0] == '0' && TOLOWER(cp
[1]) == 'x')
64 while (isxdigit(*cp
)) {
67 value
= isdigit(*cp
) ? *cp
- '0' : TOLOWER(*cp
) - 'a' + 10;
70 result
= result
* base
+ value
;
78 EXPORT_SYMBOL(simple_strtoul
);
81 * simple_strtol - convert a string to a signed long
82 * @cp: The start of the string
83 * @endp: A pointer to the end of the parsed string will be placed here
84 * @base: The number base to use
86 long simple_strtol(const char *cp
, char **endp
, unsigned int base
)
89 return -simple_strtoul(cp
+ 1, endp
, base
);
90 return simple_strtoul(cp
, endp
, base
);
92 EXPORT_SYMBOL(simple_strtol
);
95 * simple_strtoull - convert a string to an unsigned long long
96 * @cp: The start of the string
97 * @endp: A pointer to the end of the parsed string will be placed here
98 * @base: The number base to use
100 unsigned long long simple_strtoull(const char *cp
, char **endp
, unsigned int base
)
102 unsigned long long result
= 0;
105 base
= simple_guess_base(cp
);
107 if (base
== 16 && cp
[0] == '0' && TOLOWER(cp
[1]) == 'x')
110 while (isxdigit(*cp
)) {
113 value
= isdigit(*cp
) ? *cp
- '0' : TOLOWER(*cp
) - 'a' + 10;
116 result
= result
* base
+ value
;
124 EXPORT_SYMBOL(simple_strtoull
);
127 * simple_strtoll - convert a string to a signed long long
128 * @cp: The start of the string
129 * @endp: A pointer to the end of the parsed string will be placed here
130 * @base: The number base to use
132 long long simple_strtoll(const char *cp
, char **endp
, unsigned int base
)
135 return -simple_strtoull(cp
+ 1, endp
, base
);
136 return simple_strtoull(cp
, endp
, base
);
140 * strict_strtoul - convert a string to an unsigned long strictly
141 * @cp: The string to be converted
142 * @base: The number base to use
143 * @res: The converted result value
145 * strict_strtoul converts a string to an unsigned long only if the
146 * string is really an unsigned long string, any string containing
147 * any invalid char at the tail will be rejected and -EINVAL is returned,
148 * only a newline char at the tail is acceptible because people generally
149 * change a module parameter in the following way:
151 * echo 1024 > /sys/module/e1000/parameters/copybreak
153 * echo will append a newline to the tail.
155 * It returns 0 if conversion is successful and *res is set to the converted
156 * value, otherwise it returns -EINVAL and *res is set to 0.
158 * simple_strtoul just ignores the successive invalid characters and
159 * return the converted value of prefix part of the string.
161 int strict_strtoul(const char *cp
, unsigned int base
, unsigned long *res
)
172 val
= simple_strtoul(cp
, &tail
, base
);
173 if ((*tail
== '\0') ||
174 ((len
== (size_t)(tail
- cp
) + 1) && (*tail
== '\n'))) {
181 EXPORT_SYMBOL(strict_strtoul
);
184 * strict_strtol - convert a string to a long strictly
185 * @cp: The string to be converted
186 * @base: The number base to use
187 * @res: The converted result value
189 * strict_strtol is similiar to strict_strtoul, but it allows the first
190 * character of a string is '-'.
192 * It returns 0 if conversion is successful and *res is set to the converted
193 * value, otherwise it returns -EINVAL and *res is set to 0.
195 int strict_strtol(const char *cp
, unsigned int base
, long *res
)
199 ret
= strict_strtoul(cp
+ 1, base
, (unsigned long *)res
);
203 ret
= strict_strtoul(cp
, base
, (unsigned long *)res
);
208 EXPORT_SYMBOL(strict_strtol
);
211 * strict_strtoull - convert a string to an unsigned long long strictly
212 * @cp: The string to be converted
213 * @base: The number base to use
214 * @res: The converted result value
216 * strict_strtoull converts a string to an unsigned long long only if the
217 * string is really an unsigned long long string, any string containing
218 * any invalid char at the tail will be rejected and -EINVAL is returned,
219 * only a newline char at the tail is acceptible because people generally
220 * change a module parameter in the following way:
222 * echo 1024 > /sys/module/e1000/parameters/copybreak
224 * echo will append a newline to the tail of the string.
226 * It returns 0 if conversion is successful and *res is set to the converted
227 * value, otherwise it returns -EINVAL and *res is set to 0.
229 * simple_strtoull just ignores the successive invalid characters and
230 * return the converted value of prefix part of the string.
232 int strict_strtoull(const char *cp
, unsigned int base
, unsigned long long *res
)
235 unsigned long long val
;
243 val
= simple_strtoull(cp
, &tail
, base
);
244 if ((*tail
== '\0') ||
245 ((len
== (size_t)(tail
- cp
) + 1) && (*tail
== '\n'))) {
252 EXPORT_SYMBOL(strict_strtoull
);
255 * strict_strtoll - convert a string to a long long strictly
256 * @cp: The string to be converted
257 * @base: The number base to use
258 * @res: The converted result value
260 * strict_strtoll is similiar to strict_strtoull, but it allows the first
261 * character of a string is '-'.
263 * It returns 0 if conversion is successful and *res is set to the converted
264 * value, otherwise it returns -EINVAL and *res is set to 0.
266 int strict_strtoll(const char *cp
, unsigned int base
, long long *res
)
270 ret
= strict_strtoull(cp
+ 1, base
, (unsigned long long *)res
);
274 ret
= strict_strtoull(cp
, base
, (unsigned long long *)res
);
279 EXPORT_SYMBOL(strict_strtoll
);
281 static int skip_atoi(const char **s
)
286 i
= i
*10 + *((*s
)++) - '0';
290 /* Decimal conversion is by far the most typical, and is used
291 * for /proc and /sys data. This directly impacts e.g. top performance
292 * with many processes running. We optimize it for speed
294 * http://www.cs.uiowa.edu/~jones/bcd/decimal.html
295 * (with permission from the author, Douglas W. Jones). */
297 /* Formats correctly any integer in [0,99999].
298 * Outputs from one to five digits depending on input.
299 * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */
300 static char* put_dec_trunc(char *buf
, unsigned q
)
302 unsigned d3
, d2
, d1
, d0
;
307 d0
= 6*(d3
+ d2
+ d1
) + (q
& 0xf);
308 q
= (d0
* 0xcd) >> 11;
310 *buf
++ = d0
+ '0'; /* least significant digit */
311 d1
= q
+ 9*d3
+ 5*d2
+ d1
;
313 q
= (d1
* 0xcd) >> 11;
315 *buf
++ = d1
+ '0'; /* next digit */
318 if ((d2
!= 0) || (d3
!= 0)) {
321 *buf
++ = d2
+ '0'; /* next digit */
325 q
= (d3
* 0xcd) >> 11;
327 *buf
++ = d3
+ '0'; /* next digit */
329 *buf
++ = q
+ '0'; /* most sign. digit */
335 /* Same with if's removed. Always emits five digits */
336 static char* put_dec_full(char *buf
, unsigned q
)
338 /* BTW, if q is in [0,9999], 8-bit ints will be enough, */
339 /* but anyway, gcc produces better code with full-sized ints */
340 unsigned d3
, d2
, d1
, d0
;
345 /* Possible ways to approx. divide by 10 */
346 /* gcc -O2 replaces multiply with shifts and adds */
347 // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386)
348 // (x * 0x67) >> 10: 1100111
349 // (x * 0x34) >> 9: 110100 - same
350 // (x * 0x1a) >> 8: 11010 - same
351 // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386)
353 d0
= 6*(d3
+ d2
+ d1
) + (q
& 0xf);
354 q
= (d0
* 0xcd) >> 11;
357 d1
= q
+ 9*d3
+ 5*d2
+ d1
;
358 q
= (d1
* 0xcd) >> 11;
368 q
= (d3
* 0xcd) >> 11; /* - shorter code */
369 /* q = (d3 * 0x67) >> 10; - would also work */
375 /* No inlining helps gcc to use registers better */
376 static noinline
char* put_dec(char *buf
, unsigned long long num
)
381 return put_dec_trunc(buf
, num
);
382 rem
= do_div(num
, 100000);
383 buf
= put_dec_full(buf
, rem
);
387 #define ZEROPAD 1 /* pad with zero */
388 #define SIGN 2 /* unsigned/signed long */
389 #define PLUS 4 /* show plus */
390 #define SPACE 8 /* space if plus */
391 #define LEFT 16 /* left justified */
392 #define SMALL 32 /* Must be 32 == 0x20 */
393 #define SPECIAL 64 /* 0x */
395 static char *number(char *buf
, char *end
, unsigned long long num
, int base
, int size
, int precision
, int type
)
397 /* we are called with base 8, 10 or 16, only, thus don't need "G..." */
398 static const char digits
[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
403 int need_pfx
= ((type
& SPECIAL
) && base
!= 10);
406 /* locase = 0 or 0x20. ORing digits or letters with 'locase'
407 * produces same digits or (maybe lowercased) letters */
408 locase
= (type
& SMALL
);
413 if ((signed long long) num
< 0) {
415 num
= - (signed long long) num
;
417 } else if (type
& PLUS
) {
420 } else if (type
& SPACE
) {
431 /* generate full string in tmp[], in reverse order */
435 /* Generic code, for any base:
437 tmp[i++] = (digits[do_div(num,base)] | locase);
440 else if (base
!= 10) { /* 8 or 16 */
443 if (base
== 16) shift
= 4;
445 tmp
[i
++] = (digits
[((unsigned char)num
) & mask
] | locase
);
448 } else { /* base 10 */
449 i
= put_dec(tmp
, num
) - tmp
;
452 /* printing 100 using %2d gives "100", not "00" */
455 /* leading space padding */
457 if (!(type
& (ZEROPAD
+LEFT
))) {
470 /* "0x" / "0" prefix */
477 *buf
= ('X' | locase
);
481 /* zero or space padding */
482 if (!(type
& LEFT
)) {
483 char c
= (type
& ZEROPAD
) ? '0' : ' ';
484 while (--size
>= 0) {
490 /* hmm even more zero padding? */
491 while (i
<= --precision
) {
496 /* actual digits of result */
502 /* trailing space padding */
503 while (--size
>= 0) {
511 static char *string(char *buf
, char *end
, char *s
, int field_width
, int precision
, int flags
)
515 if ((unsigned long)s
< PAGE_SIZE
)
518 len
= strnlen(s
, precision
);
520 if (!(flags
& LEFT
)) {
521 while (len
< field_width
--) {
527 for (i
= 0; i
< len
; ++i
) {
532 while (len
< field_width
--) {
540 static char *symbol_string(char *buf
, char *end
, void *ptr
, int field_width
, int precision
, int flags
)
542 unsigned long value
= (unsigned long) ptr
;
543 #ifdef CONFIG_KALLSYMS
544 char sym
[KSYM_SYMBOL_LEN
];
545 sprint_symbol(sym
, value
);
546 return string(buf
, end
, sym
, field_width
, precision
, flags
);
548 field_width
= 2*sizeof(void *);
549 flags
|= SPECIAL
| SMALL
| ZEROPAD
;
550 return number(buf
, end
, value
, 16, field_width
, precision
, flags
);
554 static char *resource_string(char *buf
, char *end
, struct resource
*res
, int field_width
, int precision
, int flags
)
556 #ifndef IO_RSRC_PRINTK_SIZE
557 #define IO_RSRC_PRINTK_SIZE 4
560 #ifndef MEM_RSRC_PRINTK_SIZE
561 #define MEM_RSRC_PRINTK_SIZE 8
564 /* room for the actual numbers, the two "0x", -, [, ] and the final zero */
565 char sym
[4*sizeof(resource_size_t
) + 8];
566 char *p
= sym
, *pend
= sym
+ sizeof(sym
);
569 if (res
->flags
& IORESOURCE_IO
)
570 size
= IO_RSRC_PRINTK_SIZE
;
571 else if (res
->flags
& IORESOURCE_MEM
)
572 size
= MEM_RSRC_PRINTK_SIZE
;
575 p
= number(p
, pend
, res
->start
, 16, size
, -1, SPECIAL
| SMALL
| ZEROPAD
);
577 p
= number(p
, pend
, res
->end
, 16, size
, -1, SPECIAL
| SMALL
| ZEROPAD
);
581 return string(buf
, end
, sym
, field_width
, precision
, flags
);
584 static char *mac_address_string(char *buf
, char *end
, u8
*addr
, int field_width
,
585 int precision
, int flags
)
587 char mac_addr
[6 * 3]; /* (6 * 2 hex digits), 5 colons and trailing zero */
591 for (i
= 0; i
< 6; i
++) {
592 p
= pack_hex_byte(p
, addr
[i
]);
593 if (!(flags
& SPECIAL
) && i
!= 5)
598 return string(buf
, end
, mac_addr
, field_width
, precision
, flags
& ~SPECIAL
);
602 * Show a '%p' thing. A kernel extension is that the '%p' is followed
603 * by an extra set of alphanumeric characters that are extended format
606 * Right now we handle:
608 * - 'F' For symbolic function descriptor pointers
609 * - 'S' For symbolic direct pointers
610 * - 'R' For a struct resource pointer, it prints the range of
611 * addresses (not the name nor the flags)
612 * - 'M' For a 6-byte MAC address, it prints the address in the
613 * usual colon-separated hex notation
615 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
616 * function pointers are really function descriptors, which contain a
617 * pointer to the real address.
619 static char *pointer(const char *fmt
, char *buf
, char *end
, void *ptr
, int field_width
, int precision
, int flags
)
623 ptr
= dereference_function_descriptor(ptr
);
626 return symbol_string(buf
, end
, ptr
, field_width
, precision
, flags
);
628 return resource_string(buf
, end
, ptr
, field_width
, precision
, flags
);
630 return mac_address_string(buf
, end
, ptr
, field_width
, precision
, flags
);
633 if (field_width
== -1) {
634 field_width
= 2*sizeof(void *);
637 return number(buf
, end
, (unsigned long) ptr
, 16, field_width
, precision
, flags
);
641 * vsnprintf - Format a string and place it in a buffer
642 * @buf: The buffer to place the result into
643 * @size: The size of the buffer, including the trailing null space
644 * @fmt: The format string to use
645 * @args: Arguments for the format string
647 * This function follows C99 vsnprintf, but has some extensions:
648 * %pS output the name of a text symbol
649 * %pF output the name of a function pointer
650 * %pR output the address range in a struct resource
652 * The return value is the number of characters which would
653 * be generated for the given input, excluding the trailing
654 * '\0', as per ISO C99. If you want to have the exact
655 * number of characters written into @buf as return value
656 * (not including the trailing '\0'), use vscnprintf(). If the
657 * return is greater than or equal to @size, the resulting
658 * string is truncated.
660 * Call this function if you are already dealing with a va_list.
661 * You probably want snprintf() instead.
663 int vsnprintf(char *buf
, size_t size
, const char *fmt
, va_list args
)
665 unsigned long long num
;
669 int flags
; /* flags to number() */
671 int field_width
; /* width of output field */
672 int precision
; /* min. # of digits for integers; max
673 number of chars for from string */
674 int qualifier
; /* 'h', 'l', or 'L' for integer fields */
675 /* 'z' support added 23/7/1999 S.H. */
676 /* 'z' changed to 'Z' --davidm 1/25/99 */
677 /* 't' added for ptrdiff_t */
679 /* Reject out-of-range values early. Large positive sizes are
680 used for unknown buffer sizes. */
681 if (unlikely((int) size
< 0)) {
682 /* There can be only one.. */
683 static char warn
= 1;
692 /* Make sure end is always >= buf */
698 for (; *fmt
; ++fmt
) {
709 ++fmt
; /* this also skips first '%' */
711 case '-': flags
|= LEFT
; goto repeat
;
712 case '+': flags
|= PLUS
; goto repeat
;
713 case ' ': flags
|= SPACE
; goto repeat
;
714 case '#': flags
|= SPECIAL
; goto repeat
;
715 case '0': flags
|= ZEROPAD
; goto repeat
;
718 /* get field width */
721 field_width
= skip_atoi(&fmt
);
722 else if (*fmt
== '*') {
724 /* it's the next argument */
725 field_width
= va_arg(args
, int);
726 if (field_width
< 0) {
727 field_width
= -field_width
;
732 /* get the precision */
737 precision
= skip_atoi(&fmt
);
738 else if (*fmt
== '*') {
740 /* it's the next argument */
741 precision
= va_arg(args
, int);
747 /* get the conversion qualifier */
749 if (*fmt
== 'h' || *fmt
== 'l' || *fmt
== 'L' ||
750 *fmt
=='Z' || *fmt
== 'z' || *fmt
== 't') {
753 if (qualifier
== 'l' && *fmt
== 'l') {
764 if (!(flags
& LEFT
)) {
765 while (--field_width
> 0) {
771 c
= (unsigned char) va_arg(args
, int);
775 while (--field_width
> 0) {
783 str
= string(str
, end
, va_arg(args
, char *), field_width
, precision
, flags
);
787 str
= pointer(fmt
+1, str
, end
,
788 va_arg(args
, void *),
789 field_width
, precision
, flags
);
790 /* Skip all alphanumeric pointer suffixes */
791 while (isalnum(fmt
[1]))
797 * What does C99 say about the overflow case here? */
798 if (qualifier
== 'l') {
799 long * ip
= va_arg(args
, long *);
801 } else if (qualifier
== 'Z' || qualifier
== 'z') {
802 size_t * ip
= va_arg(args
, size_t *);
805 int * ip
= va_arg(args
, int *);
816 /* integer number formats - set up the flags and "break" */
846 if (qualifier
== 'L')
847 num
= va_arg(args
, long long);
848 else if (qualifier
== 'l') {
849 num
= va_arg(args
, unsigned long);
851 num
= (signed long) num
;
852 } else if (qualifier
== 'Z' || qualifier
== 'z') {
853 num
= va_arg(args
, size_t);
854 } else if (qualifier
== 't') {
855 num
= va_arg(args
, ptrdiff_t);
856 } else if (qualifier
== 'h') {
857 num
= (unsigned short) va_arg(args
, int);
859 num
= (signed short) num
;
861 num
= va_arg(args
, unsigned int);
863 num
= (signed int) num
;
865 str
= number(str
, end
, num
, base
,
866 field_width
, precision
, flags
);
874 /* the trailing null byte doesn't count towards the total */
877 EXPORT_SYMBOL(vsnprintf
);
880 * vscnprintf - Format a string and place it in a buffer
881 * @buf: The buffer to place the result into
882 * @size: The size of the buffer, including the trailing null space
883 * @fmt: The format string to use
884 * @args: Arguments for the format string
886 * The return value is the number of characters which have been written into
887 * the @buf not including the trailing '\0'. If @size is <= 0 the function
890 * Call this function if you are already dealing with a va_list.
891 * You probably want scnprintf() instead.
893 * See the vsnprintf() documentation for format string extensions over C99.
895 int vscnprintf(char *buf
, size_t size
, const char *fmt
, va_list args
)
899 i
=vsnprintf(buf
,size
,fmt
,args
);
900 return (i
>= size
) ? (size
- 1) : i
;
902 EXPORT_SYMBOL(vscnprintf
);
905 * snprintf - Format a string and place it in a buffer
906 * @buf: The buffer to place the result into
907 * @size: The size of the buffer, including the trailing null space
908 * @fmt: The format string to use
909 * @...: Arguments for the format string
911 * The return value is the number of characters which would be
912 * generated for the given input, excluding the trailing null,
913 * as per ISO C99. If the return is greater than or equal to
914 * @size, the resulting string is truncated.
916 * See the vsnprintf() documentation for format string extensions over C99.
918 int snprintf(char * buf
, size_t size
, const char *fmt
, ...)
924 i
=vsnprintf(buf
,size
,fmt
,args
);
928 EXPORT_SYMBOL(snprintf
);
931 * scnprintf - Format a string and place it in a buffer
932 * @buf: The buffer to place the result into
933 * @size: The size of the buffer, including the trailing null space
934 * @fmt: The format string to use
935 * @...: Arguments for the format string
937 * The return value is the number of characters written into @buf not including
938 * the trailing '\0'. If @size is <= 0 the function returns 0.
941 int scnprintf(char * buf
, size_t size
, const char *fmt
, ...)
947 i
= vsnprintf(buf
, size
, fmt
, args
);
949 return (i
>= size
) ? (size
- 1) : i
;
951 EXPORT_SYMBOL(scnprintf
);
954 * vsprintf - Format a string and place it in a buffer
955 * @buf: The buffer to place the result into
956 * @fmt: The format string to use
957 * @args: Arguments for the format string
959 * The function returns the number of characters written
960 * into @buf. Use vsnprintf() or vscnprintf() in order to avoid
963 * Call this function if you are already dealing with a va_list.
964 * You probably want sprintf() instead.
966 * See the vsnprintf() documentation for format string extensions over C99.
968 int vsprintf(char *buf
, const char *fmt
, va_list args
)
970 return vsnprintf(buf
, INT_MAX
, fmt
, args
);
972 EXPORT_SYMBOL(vsprintf
);
975 * sprintf - Format a string and place it in a buffer
976 * @buf: The buffer to place the result into
977 * @fmt: The format string to use
978 * @...: Arguments for the format string
980 * The function returns the number of characters written
981 * into @buf. Use snprintf() or scnprintf() in order to avoid
984 * See the vsnprintf() documentation for format string extensions over C99.
986 int sprintf(char * buf
, const char *fmt
, ...)
992 i
=vsnprintf(buf
, INT_MAX
, fmt
, args
);
996 EXPORT_SYMBOL(sprintf
);
999 * vsscanf - Unformat a buffer into a list of arguments
1000 * @buf: input buffer
1001 * @fmt: format of buffer
1004 int vsscanf(const char * buf
, const char * fmt
, va_list args
)
1006 const char *str
= buf
;
1015 while(*fmt
&& *str
) {
1016 /* skip any white space in format */
1017 /* white space in format matchs any amount of
1018 * white space, including none, in the input.
1020 if (isspace(*fmt
)) {
1021 while (isspace(*fmt
))
1023 while (isspace(*str
))
1027 /* anything that is not a conversion must match exactly */
1028 if (*fmt
!= '%' && *fmt
) {
1029 if (*fmt
++ != *str
++)
1038 /* skip this conversion.
1039 * advance both strings to next white space
1042 while (!isspace(*fmt
) && *fmt
)
1044 while (!isspace(*str
) && *str
)
1049 /* get field width */
1052 field_width
= skip_atoi(&fmt
);
1054 /* get conversion qualifier */
1056 if (*fmt
== 'h' || *fmt
== 'l' || *fmt
== 'L' ||
1057 *fmt
== 'Z' || *fmt
== 'z') {
1059 if (unlikely(qualifier
== *fmt
)) {
1060 if (qualifier
== 'h') {
1063 } else if (qualifier
== 'l') {
1078 char *s
= (char *) va_arg(args
,char*);
1079 if (field_width
== -1)
1083 } while (--field_width
> 0 && *str
);
1089 char *s
= (char *) va_arg(args
, char *);
1090 if(field_width
== -1)
1091 field_width
= INT_MAX
;
1092 /* first, skip leading white space in buffer */
1093 while (isspace(*str
))
1096 /* now copy until next white space */
1097 while (*str
&& !isspace(*str
) && field_width
--) {
1105 /* return number of characters read so far */
1107 int *i
= (int *)va_arg(args
,int*);
1125 /* looking for '%' in str */
1130 /* invalid format; stop here */
1134 /* have some sort of integer conversion.
1135 * first, skip white space in buffer.
1137 while (isspace(*str
))
1141 if (is_sign
&& digit
== '-')
1145 || (base
== 16 && !isxdigit(digit
))
1146 || (base
== 10 && !isdigit(digit
))
1147 || (base
== 8 && (!isdigit(digit
) || digit
> '7'))
1148 || (base
== 0 && !isdigit(digit
)))
1152 case 'H': /* that's 'hh' in format */
1154 signed char *s
= (signed char *) va_arg(args
,signed char *);
1155 *s
= (signed char) simple_strtol(str
,&next
,base
);
1157 unsigned char *s
= (unsigned char *) va_arg(args
, unsigned char *);
1158 *s
= (unsigned char) simple_strtoul(str
, &next
, base
);
1163 short *s
= (short *) va_arg(args
,short *);
1164 *s
= (short) simple_strtol(str
,&next
,base
);
1166 unsigned short *s
= (unsigned short *) va_arg(args
, unsigned short *);
1167 *s
= (unsigned short) simple_strtoul(str
, &next
, base
);
1172 long *l
= (long *) va_arg(args
,long *);
1173 *l
= simple_strtol(str
,&next
,base
);
1175 unsigned long *l
= (unsigned long*) va_arg(args
,unsigned long*);
1176 *l
= simple_strtoul(str
,&next
,base
);
1181 long long *l
= (long long*) va_arg(args
,long long *);
1182 *l
= simple_strtoll(str
,&next
,base
);
1184 unsigned long long *l
= (unsigned long long*) va_arg(args
,unsigned long long*);
1185 *l
= simple_strtoull(str
,&next
,base
);
1191 size_t *s
= (size_t*) va_arg(args
,size_t*);
1192 *s
= (size_t) simple_strtoul(str
,&next
,base
);
1197 int *i
= (int *) va_arg(args
, int*);
1198 *i
= (int) simple_strtol(str
,&next
,base
);
1200 unsigned int *i
= (unsigned int*) va_arg(args
, unsigned int*);
1201 *i
= (unsigned int) simple_strtoul(str
,&next
,base
);
1213 * Now we've come all the way through so either the input string or the
1214 * format ended. In the former case, there can be a %n at the current
1215 * position in the format that needs to be filled.
1217 if (*fmt
== '%' && *(fmt
+ 1) == 'n') {
1218 int *p
= (int *)va_arg(args
, int *);
1224 EXPORT_SYMBOL(vsscanf
);
1227 * sscanf - Unformat a buffer into a list of arguments
1228 * @buf: input buffer
1229 * @fmt: formatting of buffer
1230 * @...: resulting arguments
1232 int sscanf(const char * buf
, const char * fmt
, ...)
1238 i
= vsscanf(buf
,fmt
,args
);
1242 EXPORT_SYMBOL(sscanf
);