Commit dc4d629f authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] Teach sscanf about 'hh' and 'll'

Adds support for 'hh' (store number in char *) and 'll' (proper C99 for
long long) modifiers to sscanf().
parent 6244f13c
...@@ -668,9 +668,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -668,9 +668,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
qualifier = -1; qualifier = -1;
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
*fmt == 'Z' || *fmt == 'z') { *fmt == 'Z' || *fmt == 'z') {
qualifier = *fmt; qualifier = *fmt++;
if (unlikely(qualifier == *fmt)) {
if (qualifier == 'h') {
qualifier = 'H';
fmt++;
} else if (qualifier == 'l') {
qualifier = 'L';
fmt++; fmt++;
} }
}
}
base = 10; base = 10;
is_sign = 0; is_sign = 0;
...@@ -754,6 +762,15 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -754,6 +762,15 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
break; break;
switch(qualifier) { switch(qualifier) {
case 'H': /* that's 'hh' in format */
if (is_sign) {
signed char *s = (signed char *) va_arg(args,signed char *);
*s = (signed char) simple_strtol(str,&next,base);
} else {
unsigned char *s = (unsigned char *) va_arg(args, unsigned char *);
*s = (unsigned char) simple_strtoul(str, &next, base);
}
break;
case 'h': case 'h':
if (is_sign) { if (is_sign) {
short *s = (short *) va_arg(args,short *); short *s = (short *) va_arg(args,short *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment