diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig.debug | 2 | ||||
-rw-r--r-- | lib/argv_split.c | 13 | ||||
-rw-r--r-- | lib/crc32.c | 121 | ||||
-rw-r--r-- | lib/ctype.c | 50 | ||||
-rw-r--r-- | lib/dynamic_debug.c | 4 | ||||
-rw-r--r-- | lib/parser.c | 11 | ||||
-rw-r--r-- | lib/rwsem-spinlock.c | 23 | ||||
-rw-r--r-- | lib/string.c | 25 | ||||
-rw-r--r-- | lib/vsprintf.c | 395 |
9 files changed, 332 insertions, 312 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 2f22cf4576db..8cf9938dd147 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -575,7 +575,7 @@ config DEBUG_BUGVERBOSE | |||
575 | depends on BUG | 575 | depends on BUG |
576 | depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \ | 576 | depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \ |
577 | FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 | 577 | FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 |
578 | default !EMBEDDED | 578 | default y |
579 | help | 579 | help |
580 | Say Y here to make BUG() panics output the file name and line number | 580 | Say Y here to make BUG() panics output the file name and line number |
581 | of the BUG call as well as the EIP and oops trace. This aids | 581 | of the BUG call as well as the EIP and oops trace. This aids |
diff --git a/lib/argv_split.c b/lib/argv_split.c index 5205a8dae5bc..4b1b083f219c 100644 --- a/lib/argv_split.c +++ b/lib/argv_split.c | |||
@@ -4,17 +4,10 @@ | |||
4 | 4 | ||
5 | #include <linux/kernel.h> | 5 | #include <linux/kernel.h> |
6 | #include <linux/ctype.h> | 6 | #include <linux/ctype.h> |
7 | #include <linux/string.h> | ||
7 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
8 | #include <linux/module.h> | 9 | #include <linux/module.h> |
9 | 10 | ||
10 | static const char *skip_sep(const char *cp) | ||
11 | { | ||
12 | while (*cp && isspace(*cp)) | ||
13 | cp++; | ||
14 | |||
15 | return cp; | ||
16 | } | ||
17 | |||
18 | static const char *skip_arg(const char *cp) | 11 | static const char *skip_arg(const char *cp) |
19 | { | 12 | { |
20 | while (*cp && !isspace(*cp)) | 13 | while (*cp && !isspace(*cp)) |
@@ -28,7 +21,7 @@ static int count_argc(const char *str) | |||
28 | int count = 0; | 21 | int count = 0; |
29 | 22 | ||
30 | while (*str) { | 23 | while (*str) { |
31 | str = skip_sep(str); | 24 | str = skip_spaces(str); |
32 | if (*str) { | 25 | if (*str) { |
33 | count++; | 26 | count++; |
34 | str = skip_arg(str); | 27 | str = skip_arg(str); |
@@ -82,7 +75,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp) | |||
82 | argvp = argv; | 75 | argvp = argv; |
83 | 76 | ||
84 | while (*str) { | 77 | while (*str) { |
85 | str = skip_sep(str); | 78 | str = skip_spaces(str); |
86 | 79 | ||
87 | if (*str) { | 80 | if (*str) { |
88 | const char *p = str; | 81 | const char *p = str; |
diff --git a/lib/crc32.c b/lib/crc32.c index 49d1c9e3ce38..02e3b31b3a79 100644 --- a/lib/crc32.c +++ b/lib/crc32.c | |||
@@ -42,6 +42,48 @@ MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>"); | |||
42 | MODULE_DESCRIPTION("Ethernet CRC32 calculations"); | 42 | MODULE_DESCRIPTION("Ethernet CRC32 calculations"); |
43 | MODULE_LICENSE("GPL"); | 43 | MODULE_LICENSE("GPL"); |
44 | 44 | ||
45 | #if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 | ||
46 | |||
47 | static inline u32 | ||
48 | crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | ||
49 | { | ||
50 | # ifdef __LITTLE_ENDIAN | ||
51 | # define DO_CRC(x) crc = tab[(crc ^ (x)) & 255 ] ^ (crc >> 8) | ||
52 | # else | ||
53 | # define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8) | ||
54 | # endif | ||
55 | const u32 *b = (const u32 *)buf; | ||
56 | size_t rem_len; | ||
57 | |||
58 | /* Align it */ | ||
59 | if (unlikely((long)b & 3 && len)) { | ||
60 | u8 *p = (u8 *)b; | ||
61 | do { | ||
62 | DO_CRC(*p++); | ||
63 | } while ((--len) && ((long)p)&3); | ||
64 | b = (u32 *)p; | ||
65 | } | ||
66 | rem_len = len & 3; | ||
67 | /* load data 32 bits wide, xor data 32 bits wide. */ | ||
68 | len = len >> 2; | ||
69 | for (--b; len; --len) { | ||
70 | crc ^= *++b; /* use pre increment for speed */ | ||
71 | DO_CRC(0); | ||
72 | DO_CRC(0); | ||
73 | DO_CRC(0); | ||
74 | DO_CRC(0); | ||
75 | } | ||
76 | len = rem_len; | ||
77 | /* And the last few bytes */ | ||
78 | if (len) { | ||
79 | u8 *p = (u8 *)(b + 1) - 1; | ||
80 | do { | ||
81 | DO_CRC(*++p); /* use pre increment for speed */ | ||
82 | } while (--len); | ||
83 | } | ||
84 | return crc; | ||
85 | } | ||
86 | #endif | ||
45 | /** | 87 | /** |
46 | * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32 | 88 | * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32 |
47 | * @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for | 89 | * @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for |
@@ -72,48 +114,10 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | |||
72 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | 114 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) |
73 | { | 115 | { |
74 | # if CRC_LE_BITS == 8 | 116 | # if CRC_LE_BITS == 8 |
75 | const u32 *b =(u32 *)p; | ||
76 | const u32 *tab = crc32table_le; | 117 | const u32 *tab = crc32table_le; |
77 | 118 | ||
78 | # ifdef __LITTLE_ENDIAN | ||
79 | # define DO_CRC(x) crc = tab[ (crc ^ (x)) & 255 ] ^ (crc>>8) | ||
80 | # else | ||
81 | # define DO_CRC(x) crc = tab[ ((crc >> 24) ^ (x)) & 255] ^ (crc<<8) | ||
82 | # endif | ||
83 | |||
84 | crc = __cpu_to_le32(crc); | 119 | crc = __cpu_to_le32(crc); |
85 | /* Align it */ | 120 | crc = crc32_body(crc, p, len, tab); |
86 | if(unlikely(((long)b)&3 && len)){ | ||
87 | do { | ||
88 | u8 *p = (u8 *)b; | ||
89 | DO_CRC(*p++); | ||
90 | b = (void *)p; | ||
91 | } while ((--len) && ((long)b)&3 ); | ||
92 | } | ||
93 | if(likely(len >= 4)){ | ||
94 | /* load data 32 bits wide, xor data 32 bits wide. */ | ||
95 | size_t save_len = len & 3; | ||
96 | len = len >> 2; | ||
97 | --b; /* use pre increment below(*++b) for speed */ | ||
98 | do { | ||
99 | crc ^= *++b; | ||
100 | DO_CRC(0); | ||
101 | DO_CRC(0); | ||
102 | DO_CRC(0); | ||
103 | DO_CRC(0); | ||
104 | } while (--len); | ||
105 | b++; /* point to next byte(s) */ | ||
106 | len = save_len; | ||
107 | } | ||
108 | /* And the last few bytes */ | ||
109 | if(len){ | ||
110 | do { | ||
111 | u8 *p = (u8 *)b; | ||
112 | DO_CRC(*p++); | ||
113 | b = (void *)p; | ||
114 | } while (--len); | ||
115 | } | ||
116 | |||
117 | return __le32_to_cpu(crc); | 121 | return __le32_to_cpu(crc); |
118 | #undef ENDIAN_SHIFT | 122 | #undef ENDIAN_SHIFT |
119 | #undef DO_CRC | 123 | #undef DO_CRC |
@@ -170,47 +174,10 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | |||
170 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | 174 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) |
171 | { | 175 | { |
172 | # if CRC_BE_BITS == 8 | 176 | # if CRC_BE_BITS == 8 |
173 | const u32 *b =(u32 *)p; | ||
174 | const u32 *tab = crc32table_be; | 177 | const u32 *tab = crc32table_be; |
175 | 178 | ||
176 | # ifdef __LITTLE_ENDIAN | ||
177 | # define DO_CRC(x) crc = tab[ (crc ^ (x)) & 255 ] ^ (crc>>8) | ||
178 | # else | ||
179 | # define DO_CRC(x) crc = tab[ ((crc >> 24) ^ (x)) & 255] ^ (crc<<8) | ||
180 | # endif | ||
181 | |||
182 | crc = __cpu_to_be32(crc); | 179 | crc = __cpu_to_be32(crc); |
183 | /* Align it */ | 180 | crc = crc32_body(crc, p, len, tab); |
184 | if(unlikely(((long)b)&3 && len)){ | ||
185 | do { | ||
186 | u8 *p = (u8 *)b; | ||
187 | DO_CRC(*p++); | ||
188 | b = (u32 *)p; | ||
189 | } while ((--len) && ((long)b)&3 ); | ||
190 | } | ||
191 | if(likely(len >= 4)){ | ||
192 | /* load data 32 bits wide, xor data 32 bits wide. */ | ||
193 | size_t save_len = len & 3; | ||
194 | len = len >> 2; | ||
195 | --b; /* use pre increment below(*++b) for speed */ | ||
196 | do { | ||
197 | crc ^= *++b; | ||
198 | DO_CRC(0); | ||
199 | DO_CRC(0); | ||
200 | DO_CRC(0); | ||
201 | DO_CRC(0); | ||
202 | } while (--len); | ||
203 | b++; /* point to next byte(s) */ | ||
204 | len = save_len; | ||
205 | } | ||
206 | /* And the last few bytes */ | ||
207 | if(len){ | ||
208 | do { | ||
209 | u8 *p = (u8 *)b; | ||
210 | DO_CRC(*p++); | ||
211 | b = (void *)p; | ||
212 | } while (--len); | ||
213 | } | ||
214 | return __be32_to_cpu(crc); | 181 | return __be32_to_cpu(crc); |
215 | #undef ENDIAN_SHIFT | 182 | #undef ENDIAN_SHIFT |
216 | #undef DO_CRC | 183 | #undef DO_CRC |
diff --git a/lib/ctype.c b/lib/ctype.c index d02ace14a322..26baa620e95b 100644 --- a/lib/ctype.c +++ b/lib/ctype.c | |||
@@ -7,30 +7,30 @@ | |||
7 | #include <linux/ctype.h> | 7 | #include <linux/ctype.h> |
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | 9 | ||
10 | unsigned char _ctype[] = { | 10 | const unsigned char _ctype[] = { |
11 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ | 11 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ |
12 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ | 12 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ |
13 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ | 13 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ |
14 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ | 14 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ |
15 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ | 15 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ |
16 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ | 16 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ |
17 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ | 17 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ |
18 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ | 18 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ |
19 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ | 19 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ |
20 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ | 20 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ |
21 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ | 21 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ |
22 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ | 22 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ |
23 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ | 23 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ |
24 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ | 24 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ |
25 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ | 25 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ |
26 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ | 26 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ |
27 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ | 27 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ |
28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ | 28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ |
29 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ | 29 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ |
30 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ | 30 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ |
31 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ | 31 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ |
32 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ | 32 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ |
33 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ | 33 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ |
34 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ | 34 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ |
35 | 35 | ||
36 | EXPORT_SYMBOL(_ctype); | 36 | EXPORT_SYMBOL(_ctype); |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index e22c148e4b7f..f93502915988 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/list.h> | 21 | #include <linux/list.h> |
22 | #include <linux/sysctl.h> | 22 | #include <linux/sysctl.h> |
23 | #include <linux/ctype.h> | 23 | #include <linux/ctype.h> |
24 | #include <linux/string.h> | ||
24 | #include <linux/uaccess.h> | 25 | #include <linux/uaccess.h> |
25 | #include <linux/dynamic_debug.h> | 26 | #include <linux/dynamic_debug.h> |
26 | #include <linux/debugfs.h> | 27 | #include <linux/debugfs.h> |
@@ -209,8 +210,7 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords) | |||
209 | char *end; | 210 | char *end; |
210 | 211 | ||
211 | /* Skip leading whitespace */ | 212 | /* Skip leading whitespace */ |
212 | while (*buf && isspace(*buf)) | 213 | buf = skip_spaces(buf); |
213 | buf++; | ||
214 | if (!*buf) | 214 | if (!*buf) |
215 | break; /* oh, it was trailing whitespace */ | 215 | break; /* oh, it was trailing whitespace */ |
216 | 216 | ||
diff --git a/lib/parser.c b/lib/parser.c index b00d02059a5f..fb34977246bb 100644 --- a/lib/parser.c +++ b/lib/parser.c | |||
@@ -56,13 +56,16 @@ static int match_one(char *s, const char *p, substring_t args[]) | |||
56 | 56 | ||
57 | args[argc].from = s; | 57 | args[argc].from = s; |
58 | switch (*p++) { | 58 | switch (*p++) { |
59 | case 's': | 59 | case 's': { |
60 | if (strlen(s) == 0) | 60 | size_t str_len = strlen(s); |
61 | |||
62 | if (str_len == 0) | ||
61 | return 0; | 63 | return 0; |
62 | else if (len == -1 || len > strlen(s)) | 64 | if (len == -1 || len > str_len) |
63 | len = strlen(s); | 65 | len = str_len; |
64 | args[argc].to = s + len; | 66 | args[argc].to = s + len; |
65 | break; | 67 | break; |
68 | } | ||
66 | case 'd': | 69 | case 'd': |
67 | simple_strtol(s, &args[argc].to, 0); | 70 | simple_strtol(s, &args[argc].to, 0); |
68 | goto num; | 71 | goto num; |
diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c index 9df3ca56db11..ccf95bff7984 100644 --- a/lib/rwsem-spinlock.c +++ b/lib/rwsem-spinlock.c | |||
@@ -17,6 +17,19 @@ struct rwsem_waiter { | |||
17 | #define RWSEM_WAITING_FOR_WRITE 0x00000002 | 17 | #define RWSEM_WAITING_FOR_WRITE 0x00000002 |
18 | }; | 18 | }; |
19 | 19 | ||
20 | int rwsem_is_locked(struct rw_semaphore *sem) | ||
21 | { | ||
22 | int ret = 1; | ||
23 | unsigned long flags; | ||
24 | |||
25 | if (spin_trylock_irqsave(&sem->wait_lock, flags)) { | ||
26 | ret = (sem->activity != 0); | ||
27 | spin_unlock_irqrestore(&sem->wait_lock, flags); | ||
28 | } | ||
29 | return ret; | ||
30 | } | ||
31 | EXPORT_SYMBOL(rwsem_is_locked); | ||
32 | |||
20 | /* | 33 | /* |
21 | * initialise the semaphore | 34 | * initialise the semaphore |
22 | */ | 35 | */ |
@@ -34,6 +47,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, | |||
34 | spin_lock_init(&sem->wait_lock); | 47 | spin_lock_init(&sem->wait_lock); |
35 | INIT_LIST_HEAD(&sem->wait_list); | 48 | INIT_LIST_HEAD(&sem->wait_list); |
36 | } | 49 | } |
50 | EXPORT_SYMBOL(__init_rwsem); | ||
37 | 51 | ||
38 | /* | 52 | /* |
39 | * handle the lock release when processes blocked on it that can now run | 53 | * handle the lock release when processes blocked on it that can now run |
@@ -305,12 +319,3 @@ void __downgrade_write(struct rw_semaphore *sem) | |||
305 | spin_unlock_irqrestore(&sem->wait_lock, flags); | 319 | spin_unlock_irqrestore(&sem->wait_lock, flags); |
306 | } | 320 | } |
307 | 321 | ||
308 | EXPORT_SYMBOL(__init_rwsem); | ||
309 | EXPORT_SYMBOL(__down_read); | ||
310 | EXPORT_SYMBOL(__down_read_trylock); | ||
311 | EXPORT_SYMBOL(__down_write_nested); | ||
312 | EXPORT_SYMBOL(__down_write); | ||
313 | EXPORT_SYMBOL(__down_write_trylock); | ||
314 | EXPORT_SYMBOL(__up_read); | ||
315 | EXPORT_SYMBOL(__up_write); | ||
316 | EXPORT_SYMBOL(__downgrade_write); | ||
diff --git a/lib/string.c b/lib/string.c index e96421ab9a9a..afce96af3afd 100644 --- a/lib/string.c +++ b/lib/string.c | |||
@@ -338,20 +338,34 @@ EXPORT_SYMBOL(strnchr); | |||
338 | #endif | 338 | #endif |
339 | 339 | ||
340 | /** | 340 | /** |
341 | * strstrip - Removes leading and trailing whitespace from @s. | 341 | * skip_spaces - Removes leading whitespace from @s. |
342 | * @s: The string to be stripped. | ||
343 | * | ||
344 | * Returns a pointer to the first non-whitespace character in @s. | ||
345 | */ | ||
346 | char *skip_spaces(const char *str) | ||
347 | { | ||
348 | while (isspace(*str)) | ||
349 | ++str; | ||
350 | return (char *)str; | ||
351 | } | ||
352 | EXPORT_SYMBOL(skip_spaces); | ||
353 | |||
354 | /** | ||
355 | * strim - Removes leading and trailing whitespace from @s. | ||
342 | * @s: The string to be stripped. | 356 | * @s: The string to be stripped. |
343 | * | 357 | * |
344 | * Note that the first trailing whitespace is replaced with a %NUL-terminator | 358 | * Note that the first trailing whitespace is replaced with a %NUL-terminator |
345 | * in the given string @s. Returns a pointer to the first non-whitespace | 359 | * in the given string @s. Returns a pointer to the first non-whitespace |
346 | * character in @s. | 360 | * character in @s. |
347 | */ | 361 | */ |
348 | char *strstrip(char *s) | 362 | char *strim(char *s) |
349 | { | 363 | { |
350 | size_t size; | 364 | size_t size; |
351 | char *end; | 365 | char *end; |
352 | 366 | ||
367 | s = skip_spaces(s); | ||
353 | size = strlen(s); | 368 | size = strlen(s); |
354 | |||
355 | if (!size) | 369 | if (!size) |
356 | return s; | 370 | return s; |
357 | 371 | ||
@@ -360,12 +374,9 @@ char *strstrip(char *s) | |||
360 | end--; | 374 | end--; |
361 | *(end + 1) = '\0'; | 375 | *(end + 1) = '\0'; |
362 | 376 | ||
363 | while (*s && isspace(*s)) | ||
364 | s++; | ||
365 | |||
366 | return s; | 377 | return s; |
367 | } | 378 | } |
368 | EXPORT_SYMBOL(strstrip); | 379 | EXPORT_SYMBOL(strim); |
369 | 380 | ||
370 | #ifndef __HAVE_ARCH_STRLEN | 381 | #ifndef __HAVE_ARCH_STRLEN |
371 | /** | 382 | /** |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 6438cd5599ee..735343fc857a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) | 9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /* | 12 | /* |
13 | * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com> | 13 | * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com> |
14 | * - changed to provide snprintf and vsnprintf functions | 14 | * - changed to provide snprintf and vsnprintf functions |
15 | * So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de> | 15 | * So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de> |
@@ -47,14 +47,14 @@ static unsigned int simple_guess_base(const char *cp) | |||
47 | } | 47 | } |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * simple_strtoul - convert a string to an unsigned long | 50 | * simple_strtoull - convert a string to an unsigned long long |
51 | * @cp: The start of the string | 51 | * @cp: The start of the string |
52 | * @endp: A pointer to the end of the parsed string will be placed here | 52 | * @endp: A pointer to the end of the parsed string will be placed here |
53 | * @base: The number base to use | 53 | * @base: The number base to use |
54 | */ | 54 | */ |
55 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) | 55 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) |
56 | { | 56 | { |
57 | unsigned long result = 0; | 57 | unsigned long long result = 0; |
58 | 58 | ||
59 | if (!base) | 59 | if (!base) |
60 | base = simple_guess_base(cp); | 60 | base = simple_guess_base(cp); |
@@ -71,58 +71,39 @@ unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) | |||
71 | result = result * base + value; | 71 | result = result * base + value; |
72 | cp++; | 72 | cp++; |
73 | } | 73 | } |
74 | |||
75 | if (endp) | 74 | if (endp) |
76 | *endp = (char *)cp; | 75 | *endp = (char *)cp; |
76 | |||
77 | return result; | 77 | return result; |
78 | } | 78 | } |
79 | EXPORT_SYMBOL(simple_strtoul); | 79 | EXPORT_SYMBOL(simple_strtoull); |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * simple_strtol - convert a string to a signed long | 82 | * simple_strtoul - convert a string to an unsigned long |
83 | * @cp: The start of the string | 83 | * @cp: The start of the string |
84 | * @endp: A pointer to the end of the parsed string will be placed here | 84 | * @endp: A pointer to the end of the parsed string will be placed here |
85 | * @base: The number base to use | 85 | * @base: The number base to use |
86 | */ | 86 | */ |
87 | long simple_strtol(const char *cp, char **endp, unsigned int base) | 87 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) |
88 | { | 88 | { |
89 | if(*cp == '-') | 89 | return simple_strtoull(cp, endp, base); |
90 | return -simple_strtoul(cp + 1, endp, base); | ||
91 | return simple_strtoul(cp, endp, base); | ||
92 | } | 90 | } |
93 | EXPORT_SYMBOL(simple_strtol); | 91 | EXPORT_SYMBOL(simple_strtoul); |
94 | 92 | ||
95 | /** | 93 | /** |
96 | * simple_strtoull - convert a string to an unsigned long long | 94 | * simple_strtol - convert a string to a signed long |
97 | * @cp: The start of the string | 95 | * @cp: The start of the string |
98 | * @endp: A pointer to the end of the parsed string will be placed here | 96 | * @endp: A pointer to the end of the parsed string will be placed here |
99 | * @base: The number base to use | 97 | * @base: The number base to use |
100 | */ | 98 | */ |
101 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) | 99 | long simple_strtol(const char *cp, char **endp, unsigned int base) |
102 | { | 100 | { |
103 | unsigned long long result = 0; | 101 | if (*cp == '-') |
104 | 102 | return -simple_strtoul(cp + 1, endp, base); | |
105 | if (!base) | ||
106 | base = simple_guess_base(cp); | ||
107 | |||
108 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') | ||
109 | cp += 2; | ||
110 | |||
111 | while (isxdigit(*cp)) { | ||
112 | unsigned int value; | ||
113 | |||
114 | value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; | ||
115 | if (value >= base) | ||
116 | break; | ||
117 | result = result * base + value; | ||
118 | cp++; | ||
119 | } | ||
120 | 103 | ||
121 | if (endp) | 104 | return simple_strtoul(cp, endp, base); |
122 | *endp = (char *)cp; | ||
123 | return result; | ||
124 | } | 105 | } |
125 | EXPORT_SYMBOL(simple_strtoull); | 106 | EXPORT_SYMBOL(simple_strtol); |
126 | 107 | ||
127 | /** | 108 | /** |
128 | * simple_strtoll - convert a string to a signed long long | 109 | * simple_strtoll - convert a string to a signed long long |
@@ -132,8 +113,9 @@ EXPORT_SYMBOL(simple_strtoull); | |||
132 | */ | 113 | */ |
133 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) | 114 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) |
134 | { | 115 | { |
135 | if(*cp=='-') | 116 | if (*cp == '-') |
136 | return -simple_strtoull(cp + 1, endp, base); | 117 | return -simple_strtoull(cp + 1, endp, base); |
118 | |||
137 | return simple_strtoull(cp, endp, base); | 119 | return simple_strtoull(cp, endp, base); |
138 | } | 120 | } |
139 | 121 | ||
@@ -173,6 +155,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) | |||
173 | val = simple_strtoul(cp, &tail, base); | 155 | val = simple_strtoul(cp, &tail, base); |
174 | if (tail == cp) | 156 | if (tail == cp) |
175 | return -EINVAL; | 157 | return -EINVAL; |
158 | |||
176 | if ((*tail == '\0') || | 159 | if ((*tail == '\0') || |
177 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | 160 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { |
178 | *res = val; | 161 | *res = val; |
@@ -285,10 +268,11 @@ EXPORT_SYMBOL(strict_strtoll); | |||
285 | 268 | ||
286 | static int skip_atoi(const char **s) | 269 | static int skip_atoi(const char **s) |
287 | { | 270 | { |
288 | int i=0; | 271 | int i = 0; |
289 | 272 | ||
290 | while (isdigit(**s)) | 273 | while (isdigit(**s)) |
291 | i = i*10 + *((*s)++) - '0'; | 274 | i = i*10 + *((*s)++) - '0'; |
275 | |||
292 | return i; | 276 | return i; |
293 | } | 277 | } |
294 | 278 | ||
@@ -302,7 +286,7 @@ static int skip_atoi(const char **s) | |||
302 | /* Formats correctly any integer in [0,99999]. | 286 | /* Formats correctly any integer in [0,99999]. |
303 | * Outputs from one to five digits depending on input. | 287 | * Outputs from one to five digits depending on input. |
304 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ | 288 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ |
305 | static char* put_dec_trunc(char *buf, unsigned q) | 289 | static char *put_dec_trunc(char *buf, unsigned q) |
306 | { | 290 | { |
307 | unsigned d3, d2, d1, d0; | 291 | unsigned d3, d2, d1, d0; |
308 | d1 = (q>>4) & 0xf; | 292 | d1 = (q>>4) & 0xf; |
@@ -331,14 +315,15 @@ static char* put_dec_trunc(char *buf, unsigned q) | |||
331 | d3 = d3 - 10*q; | 315 | d3 = d3 - 10*q; |
332 | *buf++ = d3 + '0'; /* next digit */ | 316 | *buf++ = d3 + '0'; /* next digit */ |
333 | if (q != 0) | 317 | if (q != 0) |
334 | *buf++ = q + '0'; /* most sign. digit */ | 318 | *buf++ = q + '0'; /* most sign. digit */ |
335 | } | 319 | } |
336 | } | 320 | } |
337 | } | 321 | } |
322 | |||
338 | return buf; | 323 | return buf; |
339 | } | 324 | } |
340 | /* Same with if's removed. Always emits five digits */ | 325 | /* Same with if's removed. Always emits five digits */ |
341 | static char* put_dec_full(char *buf, unsigned q) | 326 | static char *put_dec_full(char *buf, unsigned q) |
342 | { | 327 | { |
343 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ | 328 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ |
344 | /* but anyway, gcc produces better code with full-sized ints */ | 329 | /* but anyway, gcc produces better code with full-sized ints */ |
@@ -347,14 +332,15 @@ static char* put_dec_full(char *buf, unsigned q) | |||
347 | d2 = (q>>8) & 0xf; | 332 | d2 = (q>>8) & 0xf; |
348 | d3 = (q>>12); | 333 | d3 = (q>>12); |
349 | 334 | ||
350 | /* Possible ways to approx. divide by 10 */ | 335 | /* |
351 | /* gcc -O2 replaces multiply with shifts and adds */ | 336 | * Possible ways to approx. divide by 10 |
352 | // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) | 337 | * gcc -O2 replaces multiply with shifts and adds |
353 | // (x * 0x67) >> 10: 1100111 | 338 | * (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) |
354 | // (x * 0x34) >> 9: 110100 - same | 339 | * (x * 0x67) >> 10: 1100111 |
355 | // (x * 0x1a) >> 8: 11010 - same | 340 | * (x * 0x34) >> 9: 110100 - same |
356 | // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | 341 | * (x * 0x1a) >> 8: 11010 - same |
357 | 342 | * (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | |
343 | */ | ||
358 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); | 344 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); |
359 | q = (d0 * 0xcd) >> 11; | 345 | q = (d0 * 0xcd) >> 11; |
360 | d0 = d0 - 10*q; | 346 | d0 = d0 - 10*q; |
@@ -375,10 +361,11 @@ static char* put_dec_full(char *buf, unsigned q) | |||
375 | d3 = d3 - 10*q; | 361 | d3 = d3 - 10*q; |
376 | *buf++ = d3 + '0'; | 362 | *buf++ = d3 + '0'; |
377 | *buf++ = q + '0'; | 363 | *buf++ = q + '0'; |
364 | |||
378 | return buf; | 365 | return buf; |
379 | } | 366 | } |
380 | /* No inlining helps gcc to use registers better */ | 367 | /* No inlining helps gcc to use registers better */ |
381 | static noinline char* put_dec(char *buf, unsigned long long num) | 368 | static noinline char *put_dec(char *buf, unsigned long long num) |
382 | { | 369 | { |
383 | while (1) { | 370 | while (1) { |
384 | unsigned rem; | 371 | unsigned rem; |
@@ -448,9 +435,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
448 | spec.flags &= ~ZEROPAD; | 435 | spec.flags &= ~ZEROPAD; |
449 | sign = 0; | 436 | sign = 0; |
450 | if (spec.flags & SIGN) { | 437 | if (spec.flags & SIGN) { |
451 | if ((signed long long) num < 0) { | 438 | if ((signed long long)num < 0) { |
452 | sign = '-'; | 439 | sign = '-'; |
453 | num = - (signed long long) num; | 440 | num = -(signed long long)num; |
454 | spec.field_width--; | 441 | spec.field_width--; |
455 | } else if (spec.flags & PLUS) { | 442 | } else if (spec.flags & PLUS) { |
456 | sign = '+'; | 443 | sign = '+'; |
@@ -478,7 +465,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
478 | else if (spec.base != 10) { /* 8 or 16 */ | 465 | else if (spec.base != 10) { /* 8 or 16 */ |
479 | int mask = spec.base - 1; | 466 | int mask = spec.base - 1; |
480 | int shift = 3; | 467 | int shift = 3; |
481 | if (spec.base == 16) shift = 4; | 468 | |
469 | if (spec.base == 16) | ||
470 | shift = 4; | ||
482 | do { | 471 | do { |
483 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); | 472 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); |
484 | num >>= shift; | 473 | num >>= shift; |
@@ -493,7 +482,7 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
493 | /* leading space padding */ | 482 | /* leading space padding */ |
494 | spec.field_width -= spec.precision; | 483 | spec.field_width -= spec.precision; |
495 | if (!(spec.flags & (ZEROPAD+LEFT))) { | 484 | if (!(spec.flags & (ZEROPAD+LEFT))) { |
496 | while(--spec.field_width >= 0) { | 485 | while (--spec.field_width >= 0) { |
497 | if (buf < end) | 486 | if (buf < end) |
498 | *buf = ' '; | 487 | *buf = ' '; |
499 | ++buf; | 488 | ++buf; |
@@ -543,15 +532,16 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
543 | *buf = ' '; | 532 | *buf = ' '; |
544 | ++buf; | 533 | ++buf; |
545 | } | 534 | } |
535 | |||
546 | return buf; | 536 | return buf; |
547 | } | 537 | } |
548 | 538 | ||
549 | static char *string(char *buf, char *end, char *s, struct printf_spec spec) | 539 | static char *string(char *buf, char *end, const char *s, struct printf_spec spec) |
550 | { | 540 | { |
551 | int len, i; | 541 | int len, i; |
552 | 542 | ||
553 | if ((unsigned long)s < PAGE_SIZE) | 543 | if ((unsigned long)s < PAGE_SIZE) |
554 | s = "<NULL>"; | 544 | s = "(null)"; |
555 | 545 | ||
556 | len = strnlen(s, spec.precision); | 546 | len = strnlen(s, spec.precision); |
557 | 547 | ||
@@ -572,6 +562,7 @@ static char *string(char *buf, char *end, char *s, struct printf_spec spec) | |||
572 | *buf = ' '; | 562 | *buf = ' '; |
573 | ++buf; | 563 | ++buf; |
574 | } | 564 | } |
565 | |||
575 | return buf; | 566 | return buf; |
576 | } | 567 | } |
577 | 568 | ||
@@ -585,11 +576,13 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
585 | sprint_symbol(sym, value); | 576 | sprint_symbol(sym, value); |
586 | else | 577 | else |
587 | kallsyms_lookup(value, NULL, NULL, NULL, sym); | 578 | kallsyms_lookup(value, NULL, NULL, NULL, sym); |
579 | |||
588 | return string(buf, end, sym, spec); | 580 | return string(buf, end, sym, spec); |
589 | #else | 581 | #else |
590 | spec.field_width = 2*sizeof(void *); | 582 | spec.field_width = 2 * sizeof(void *); |
591 | spec.flags |= SPECIAL | SMALL | ZEROPAD; | 583 | spec.flags |= SPECIAL | SMALL | ZEROPAD; |
592 | spec.base = 16; | 584 | spec.base = 16; |
585 | |||
593 | return number(buf, end, value, spec); | 586 | return number(buf, end, value, spec); |
594 | #endif | 587 | #endif |
595 | } | 588 | } |
@@ -718,22 +711,19 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | |||
718 | if (i < 3) | 711 | if (i < 3) |
719 | *p++ = '.'; | 712 | *p++ = '.'; |
720 | } | 713 | } |
721 | |||
722 | *p = '\0'; | 714 | *p = '\0'; |
715 | |||
723 | return p; | 716 | return p; |
724 | } | 717 | } |
725 | 718 | ||
726 | static char *ip6_compressed_string(char *p, const char *addr) | 719 | static char *ip6_compressed_string(char *p, const char *addr) |
727 | { | 720 | { |
728 | int i; | 721 | int i, j, range; |
729 | int j; | ||
730 | int range; | ||
731 | unsigned char zerolength[8]; | 722 | unsigned char zerolength[8]; |
732 | int longest = 1; | 723 | int longest = 1; |
733 | int colonpos = -1; | 724 | int colonpos = -1; |
734 | u16 word; | 725 | u16 word; |
735 | u8 hi; | 726 | u8 hi, lo; |
736 | u8 lo; | ||
737 | bool needcolon = false; | 727 | bool needcolon = false; |
738 | bool useIPv4; | 728 | bool useIPv4; |
739 | struct in6_addr in6; | 729 | struct in6_addr in6; |
@@ -787,8 +777,9 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
787 | p = pack_hex_byte(p, hi); | 777 | p = pack_hex_byte(p, hi); |
788 | else | 778 | else |
789 | *p++ = hex_asc_lo(hi); | 779 | *p++ = hex_asc_lo(hi); |
780 | p = pack_hex_byte(p, lo); | ||
790 | } | 781 | } |
791 | if (hi || lo > 0x0f) | 782 | else if (lo > 0x0f) |
792 | p = pack_hex_byte(p, lo); | 783 | p = pack_hex_byte(p, lo); |
793 | else | 784 | else |
794 | *p++ = hex_asc_lo(lo); | 785 | *p++ = hex_asc_lo(lo); |
@@ -800,22 +791,23 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
800 | *p++ = ':'; | 791 | *p++ = ':'; |
801 | p = ip4_string(p, &in6.s6_addr[12], false); | 792 | p = ip4_string(p, &in6.s6_addr[12], false); |
802 | } | 793 | } |
803 | |||
804 | *p = '\0'; | 794 | *p = '\0'; |
795 | |||
805 | return p; | 796 | return p; |
806 | } | 797 | } |
807 | 798 | ||
808 | static char *ip6_string(char *p, const char *addr, const char *fmt) | 799 | static char *ip6_string(char *p, const char *addr, const char *fmt) |
809 | { | 800 | { |
810 | int i; | 801 | int i; |
802 | |||
811 | for (i = 0; i < 8; i++) { | 803 | for (i = 0; i < 8; i++) { |
812 | p = pack_hex_byte(p, *addr++); | 804 | p = pack_hex_byte(p, *addr++); |
813 | p = pack_hex_byte(p, *addr++); | 805 | p = pack_hex_byte(p, *addr++); |
814 | if (fmt[0] == 'I' && i != 7) | 806 | if (fmt[0] == 'I' && i != 7) |
815 | *p++ = ':'; | 807 | *p++ = ':'; |
816 | } | 808 | } |
817 | |||
818 | *p = '\0'; | 809 | *p = '\0'; |
810 | |||
819 | return p; | 811 | return p; |
820 | } | 812 | } |
821 | 813 | ||
@@ -842,6 +834,52 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
842 | return string(buf, end, ip4_addr, spec); | 834 | return string(buf, end, ip4_addr, spec); |
843 | } | 835 | } |
844 | 836 | ||
837 | static char *uuid_string(char *buf, char *end, const u8 *addr, | ||
838 | struct printf_spec spec, const char *fmt) | ||
839 | { | ||
840 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; | ||
841 | char *p = uuid; | ||
842 | int i; | ||
843 | static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
844 | static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; | ||
845 | const u8 *index = be; | ||
846 | bool uc = false; | ||
847 | |||
848 | switch (*(++fmt)) { | ||
849 | case 'L': | ||
850 | uc = true; /* fall-through */ | ||
851 | case 'l': | ||
852 | index = le; | ||
853 | break; | ||
854 | case 'B': | ||
855 | uc = true; | ||
856 | break; | ||
857 | } | ||
858 | |||
859 | for (i = 0; i < 16; i++) { | ||
860 | p = pack_hex_byte(p, addr[index[i]]); | ||
861 | switch (i) { | ||
862 | case 3: | ||
863 | case 5: | ||
864 | case 7: | ||
865 | case 9: | ||
866 | *p++ = '-'; | ||
867 | break; | ||
868 | } | ||
869 | } | ||
870 | |||
871 | *p = 0; | ||
872 | |||
873 | if (uc) { | ||
874 | p = uuid; | ||
875 | do { | ||
876 | *p = toupper(*p); | ||
877 | } while (*(++p)); | ||
878 | } | ||
879 | |||
880 | return string(buf, end, uuid, spec); | ||
881 | } | ||
882 | |||
845 | /* | 883 | /* |
846 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 884 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
847 | * by an extra set of alphanumeric characters that are extended format | 885 | * by an extra set of alphanumeric characters that are extended format |
@@ -866,6 +904,18 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
866 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) | 904 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) |
867 | * - 'I6c' for IPv6 addresses printed as specified by | 905 | * - 'I6c' for IPv6 addresses printed as specified by |
868 | * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt | 906 | * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt |
907 | * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form | ||
908 | * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
909 | * Options for %pU are: | ||
910 | * b big endian lower case hex (default) | ||
911 | * B big endian UPPER case hex | ||
912 | * l little endian lower case hex | ||
913 | * L little endian UPPER case hex | ||
914 | * big endian output byte order is: | ||
915 | * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15] | ||
916 | * little endian output byte order is: | ||
917 | * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15] | ||
918 | * | ||
869 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 919 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
870 | * function pointers are really function descriptors, which contain a | 920 | * function pointers are really function descriptors, which contain a |
871 | * pointer to the real address. | 921 | * pointer to the real address. |
@@ -880,9 +930,9 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
880 | case 'F': | 930 | case 'F': |
881 | case 'f': | 931 | case 'f': |
882 | ptr = dereference_function_descriptor(ptr); | 932 | ptr = dereference_function_descriptor(ptr); |
883 | case 's': | ||
884 | /* Fallthrough */ | 933 | /* Fallthrough */ |
885 | case 'S': | 934 | case 'S': |
935 | case 's': | ||
886 | return symbol_string(buf, end, ptr, spec, *fmt); | 936 | return symbol_string(buf, end, ptr, spec, *fmt); |
887 | case 'R': | 937 | case 'R': |
888 | case 'r': | 938 | case 'r': |
@@ -906,6 +956,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
906 | return ip4_addr_string(buf, end, ptr, spec, fmt); | 956 | return ip4_addr_string(buf, end, ptr, spec, fmt); |
907 | } | 957 | } |
908 | break; | 958 | break; |
959 | case 'U': | ||
960 | return uuid_string(buf, end, ptr, spec, fmt); | ||
909 | } | 961 | } |
910 | spec.flags |= SMALL; | 962 | spec.flags |= SMALL; |
911 | if (spec.field_width == -1) { | 963 | if (spec.field_width == -1) { |
@@ -1023,8 +1075,8 @@ precision: | |||
1023 | qualifier: | 1075 | qualifier: |
1024 | /* get the conversion qualifier */ | 1076 | /* get the conversion qualifier */ |
1025 | spec->qualifier = -1; | 1077 | spec->qualifier = -1; |
1026 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1078 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
1027 | *fmt == 'Z' || *fmt == 'z' || *fmt == 't') { | 1079 | TOLOWER(*fmt) == 'z' || *fmt == 't') { |
1028 | spec->qualifier = *fmt++; | 1080 | spec->qualifier = *fmt++; |
1029 | if (unlikely(spec->qualifier == *fmt)) { | 1081 | if (unlikely(spec->qualifier == *fmt)) { |
1030 | if (spec->qualifier == 'l') { | 1082 | if (spec->qualifier == 'l') { |
@@ -1091,7 +1143,7 @@ qualifier: | |||
1091 | spec->type = FORMAT_TYPE_LONG; | 1143 | spec->type = FORMAT_TYPE_LONG; |
1092 | else | 1144 | else |
1093 | spec->type = FORMAT_TYPE_ULONG; | 1145 | spec->type = FORMAT_TYPE_ULONG; |
1094 | } else if (spec->qualifier == 'Z' || spec->qualifier == 'z') { | 1146 | } else if (TOLOWER(spec->qualifier) == 'z') { |
1095 | spec->type = FORMAT_TYPE_SIZE_T; | 1147 | spec->type = FORMAT_TYPE_SIZE_T; |
1096 | } else if (spec->qualifier == 't') { | 1148 | } else if (spec->qualifier == 't') { |
1097 | spec->type = FORMAT_TYPE_PTRDIFF; | 1149 | spec->type = FORMAT_TYPE_PTRDIFF; |
@@ -1144,8 +1196,7 @@ qualifier: | |||
1144 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | 1196 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
1145 | { | 1197 | { |
1146 | unsigned long long num; | 1198 | unsigned long long num; |
1147 | char *str, *end, c; | 1199 | char *str, *end; |
1148 | int read; | ||
1149 | struct printf_spec spec = {0}; | 1200 | struct printf_spec spec = {0}; |
1150 | 1201 | ||
1151 | /* Reject out-of-range values early. Large positive sizes are | 1202 | /* Reject out-of-range values early. Large positive sizes are |
@@ -1164,8 +1215,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1164 | 1215 | ||
1165 | while (*fmt) { | 1216 | while (*fmt) { |
1166 | const char *old_fmt = fmt; | 1217 | const char *old_fmt = fmt; |
1167 | 1218 | int read = format_decode(fmt, &spec); | |
1168 | read = format_decode(fmt, &spec); | ||
1169 | 1219 | ||
1170 | fmt += read; | 1220 | fmt += read; |
1171 | 1221 | ||
@@ -1189,7 +1239,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1189 | spec.precision = va_arg(args, int); | 1239 | spec.precision = va_arg(args, int); |
1190 | break; | 1240 | break; |
1191 | 1241 | ||
1192 | case FORMAT_TYPE_CHAR: | 1242 | case FORMAT_TYPE_CHAR: { |
1243 | char c; | ||
1244 | |||
1193 | if (!(spec.flags & LEFT)) { | 1245 | if (!(spec.flags & LEFT)) { |
1194 | while (--spec.field_width > 0) { | 1246 | while (--spec.field_width > 0) { |
1195 | if (str < end) | 1247 | if (str < end) |
@@ -1208,6 +1260,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1208 | ++str; | 1260 | ++str; |
1209 | } | 1261 | } |
1210 | break; | 1262 | break; |
1263 | } | ||
1211 | 1264 | ||
1212 | case FORMAT_TYPE_STR: | 1265 | case FORMAT_TYPE_STR: |
1213 | str = string(str, end, va_arg(args, char *), spec); | 1266 | str = string(str, end, va_arg(args, char *), spec); |
@@ -1238,8 +1291,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1238 | if (qualifier == 'l') { | 1291 | if (qualifier == 'l') { |
1239 | long *ip = va_arg(args, long *); | 1292 | long *ip = va_arg(args, long *); |
1240 | *ip = (str - buf); | 1293 | *ip = (str - buf); |
1241 | } else if (qualifier == 'Z' || | 1294 | } else if (TOLOWER(qualifier) == 'z') { |
1242 | qualifier == 'z') { | ||
1243 | size_t *ip = va_arg(args, size_t *); | 1295 | size_t *ip = va_arg(args, size_t *); |
1244 | *ip = (str - buf); | 1296 | *ip = (str - buf); |
1245 | } else { | 1297 | } else { |
@@ -1322,7 +1374,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1322 | { | 1374 | { |
1323 | int i; | 1375 | int i; |
1324 | 1376 | ||
1325 | i=vsnprintf(buf,size,fmt,args); | 1377 | i = vsnprintf(buf, size, fmt, args); |
1378 | |||
1326 | return (i >= size) ? (size - 1) : i; | 1379 | return (i >= size) ? (size - 1) : i; |
1327 | } | 1380 | } |
1328 | EXPORT_SYMBOL(vscnprintf); | 1381 | EXPORT_SYMBOL(vscnprintf); |
@@ -1341,14 +1394,15 @@ EXPORT_SYMBOL(vscnprintf); | |||
1341 | * | 1394 | * |
1342 | * See the vsnprintf() documentation for format string extensions over C99. | 1395 | * See the vsnprintf() documentation for format string extensions over C99. |
1343 | */ | 1396 | */ |
1344 | int snprintf(char * buf, size_t size, const char *fmt, ...) | 1397 | int snprintf(char *buf, size_t size, const char *fmt, ...) |
1345 | { | 1398 | { |
1346 | va_list args; | 1399 | va_list args; |
1347 | int i; | 1400 | int i; |
1348 | 1401 | ||
1349 | va_start(args, fmt); | 1402 | va_start(args, fmt); |
1350 | i=vsnprintf(buf,size,fmt,args); | 1403 | i = vsnprintf(buf, size, fmt, args); |
1351 | va_end(args); | 1404 | va_end(args); |
1405 | |||
1352 | return i; | 1406 | return i; |
1353 | } | 1407 | } |
1354 | EXPORT_SYMBOL(snprintf); | 1408 | EXPORT_SYMBOL(snprintf); |
@@ -1364,7 +1418,7 @@ EXPORT_SYMBOL(snprintf); | |||
1364 | * the trailing '\0'. If @size is <= 0 the function returns 0. | 1418 | * the trailing '\0'. If @size is <= 0 the function returns 0. |
1365 | */ | 1419 | */ |
1366 | 1420 | ||
1367 | int scnprintf(char * buf, size_t size, const char *fmt, ...) | 1421 | int scnprintf(char *buf, size_t size, const char *fmt, ...) |
1368 | { | 1422 | { |
1369 | va_list args; | 1423 | va_list args; |
1370 | int i; | 1424 | int i; |
@@ -1372,6 +1426,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...) | |||
1372 | va_start(args, fmt); | 1426 | va_start(args, fmt); |
1373 | i = vsnprintf(buf, size, fmt, args); | 1427 | i = vsnprintf(buf, size, fmt, args); |
1374 | va_end(args); | 1428 | va_end(args); |
1429 | |||
1375 | return (i >= size) ? (size - 1) : i; | 1430 | return (i >= size) ? (size - 1) : i; |
1376 | } | 1431 | } |
1377 | EXPORT_SYMBOL(scnprintf); | 1432 | EXPORT_SYMBOL(scnprintf); |
@@ -1409,14 +1464,15 @@ EXPORT_SYMBOL(vsprintf); | |||
1409 | * | 1464 | * |
1410 | * See the vsnprintf() documentation for format string extensions over C99. | 1465 | * See the vsnprintf() documentation for format string extensions over C99. |
1411 | */ | 1466 | */ |
1412 | int sprintf(char * buf, const char *fmt, ...) | 1467 | int sprintf(char *buf, const char *fmt, ...) |
1413 | { | 1468 | { |
1414 | va_list args; | 1469 | va_list args; |
1415 | int i; | 1470 | int i; |
1416 | 1471 | ||
1417 | va_start(args, fmt); | 1472 | va_start(args, fmt); |
1418 | i=vsnprintf(buf, INT_MAX, fmt, args); | 1473 | i = vsnprintf(buf, INT_MAX, fmt, args); |
1419 | va_end(args); | 1474 | va_end(args); |
1475 | |||
1420 | return i; | 1476 | return i; |
1421 | } | 1477 | } |
1422 | EXPORT_SYMBOL(sprintf); | 1478 | EXPORT_SYMBOL(sprintf); |
@@ -1449,7 +1505,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args) | |||
1449 | { | 1505 | { |
1450 | struct printf_spec spec = {0}; | 1506 | struct printf_spec spec = {0}; |
1451 | char *str, *end; | 1507 | char *str, *end; |
1452 | int read; | ||
1453 | 1508 | ||
1454 | str = (char *)bin_buf; | 1509 | str = (char *)bin_buf; |
1455 | end = (char *)(bin_buf + size); | 1510 | end = (char *)(bin_buf + size); |
@@ -1474,14 +1529,15 @@ do { \ | |||
1474 | str += sizeof(type); \ | 1529 | str += sizeof(type); \ |
1475 | } while (0) | 1530 | } while (0) |
1476 | 1531 | ||
1477 | |||
1478 | while (*fmt) { | 1532 | while (*fmt) { |
1479 | read = format_decode(fmt, &spec); | 1533 | int read = format_decode(fmt, &spec); |
1480 | 1534 | ||
1481 | fmt += read; | 1535 | fmt += read; |
1482 | 1536 | ||
1483 | switch (spec.type) { | 1537 | switch (spec.type) { |
1484 | case FORMAT_TYPE_NONE: | 1538 | case FORMAT_TYPE_NONE: |
1539 | case FORMAT_TYPE_INVALID: | ||
1540 | case FORMAT_TYPE_PERCENT_CHAR: | ||
1485 | break; | 1541 | break; |
1486 | 1542 | ||
1487 | case FORMAT_TYPE_WIDTH: | 1543 | case FORMAT_TYPE_WIDTH: |
@@ -1496,13 +1552,14 @@ do { \ | |||
1496 | case FORMAT_TYPE_STR: { | 1552 | case FORMAT_TYPE_STR: { |
1497 | const char *save_str = va_arg(args, char *); | 1553 | const char *save_str = va_arg(args, char *); |
1498 | size_t len; | 1554 | size_t len; |
1555 | |||
1499 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE | 1556 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE |
1500 | || (unsigned long)save_str < PAGE_SIZE) | 1557 | || (unsigned long)save_str < PAGE_SIZE) |
1501 | save_str = "<NULL>"; | 1558 | save_str = "(null)"; |
1502 | len = strlen(save_str); | 1559 | len = strlen(save_str) + 1; |
1503 | if (str + len + 1 < end) | 1560 | if (str + len < end) |
1504 | memcpy(str, save_str, len + 1); | 1561 | memcpy(str, save_str, len); |
1505 | str += len + 1; | 1562 | str += len; |
1506 | break; | 1563 | break; |
1507 | } | 1564 | } |
1508 | 1565 | ||
@@ -1513,19 +1570,13 @@ do { \ | |||
1513 | fmt++; | 1570 | fmt++; |
1514 | break; | 1571 | break; |
1515 | 1572 | ||
1516 | case FORMAT_TYPE_PERCENT_CHAR: | ||
1517 | break; | ||
1518 | |||
1519 | case FORMAT_TYPE_INVALID: | ||
1520 | break; | ||
1521 | |||
1522 | case FORMAT_TYPE_NRCHARS: { | 1573 | case FORMAT_TYPE_NRCHARS: { |
1523 | /* skip %n 's argument */ | 1574 | /* skip %n 's argument */ |
1524 | int qualifier = spec.qualifier; | 1575 | int qualifier = spec.qualifier; |
1525 | void *skip_arg; | 1576 | void *skip_arg; |
1526 | if (qualifier == 'l') | 1577 | if (qualifier == 'l') |
1527 | skip_arg = va_arg(args, long *); | 1578 | skip_arg = va_arg(args, long *); |
1528 | else if (qualifier == 'Z' || qualifier == 'z') | 1579 | else if (TOLOWER(qualifier) == 'z') |
1529 | skip_arg = va_arg(args, size_t *); | 1580 | skip_arg = va_arg(args, size_t *); |
1530 | else | 1581 | else |
1531 | skip_arg = va_arg(args, int *); | 1582 | skip_arg = va_arg(args, int *); |
@@ -1561,8 +1612,8 @@ do { \ | |||
1561 | } | 1612 | } |
1562 | } | 1613 | } |
1563 | } | 1614 | } |
1564 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1565 | 1615 | ||
1616 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1566 | #undef save_arg | 1617 | #undef save_arg |
1567 | } | 1618 | } |
1568 | EXPORT_SYMBOL_GPL(vbin_printf); | 1619 | EXPORT_SYMBOL_GPL(vbin_printf); |
@@ -1591,11 +1642,9 @@ EXPORT_SYMBOL_GPL(vbin_printf); | |||
1591 | */ | 1642 | */ |
1592 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | 1643 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) |
1593 | { | 1644 | { |
1594 | unsigned long long num; | ||
1595 | char *str, *end, c; | ||
1596 | const char *args = (const char *)bin_buf; | ||
1597 | |||
1598 | struct printf_spec spec = {0}; | 1645 | struct printf_spec spec = {0}; |
1646 | char *str, *end; | ||
1647 | const char *args = (const char *)bin_buf; | ||
1599 | 1648 | ||
1600 | if (WARN_ON_ONCE((int) size < 0)) | 1649 | if (WARN_ON_ONCE((int) size < 0)) |
1601 | return 0; | 1650 | return 0; |
@@ -1625,10 +1674,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1625 | } | 1674 | } |
1626 | 1675 | ||
1627 | while (*fmt) { | 1676 | while (*fmt) { |
1628 | int read; | ||
1629 | const char *old_fmt = fmt; | 1677 | const char *old_fmt = fmt; |
1630 | 1678 | int read = format_decode(fmt, &spec); | |
1631 | read = format_decode(fmt, &spec); | ||
1632 | 1679 | ||
1633 | fmt += read; | 1680 | fmt += read; |
1634 | 1681 | ||
@@ -1652,7 +1699,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1652 | spec.precision = get_arg(int); | 1699 | spec.precision = get_arg(int); |
1653 | break; | 1700 | break; |
1654 | 1701 | ||
1655 | case FORMAT_TYPE_CHAR: | 1702 | case FORMAT_TYPE_CHAR: { |
1703 | char c; | ||
1704 | |||
1656 | if (!(spec.flags & LEFT)) { | 1705 | if (!(spec.flags & LEFT)) { |
1657 | while (--spec.field_width > 0) { | 1706 | while (--spec.field_width > 0) { |
1658 | if (str < end) | 1707 | if (str < end) |
@@ -1670,11 +1719,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1670 | ++str; | 1719 | ++str; |
1671 | } | 1720 | } |
1672 | break; | 1721 | break; |
1722 | } | ||
1673 | 1723 | ||
1674 | case FORMAT_TYPE_STR: { | 1724 | case FORMAT_TYPE_STR: { |
1675 | const char *str_arg = args; | 1725 | const char *str_arg = args; |
1676 | size_t len = strlen(str_arg); | 1726 | args += strlen(str_arg) + 1; |
1677 | args += len + 1; | ||
1678 | str = string(str, end, (char *)str_arg, spec); | 1727 | str = string(str, end, (char *)str_arg, spec); |
1679 | break; | 1728 | break; |
1680 | } | 1729 | } |
@@ -1686,11 +1735,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1686 | break; | 1735 | break; |
1687 | 1736 | ||
1688 | case FORMAT_TYPE_PERCENT_CHAR: | 1737 | case FORMAT_TYPE_PERCENT_CHAR: |
1689 | if (str < end) | ||
1690 | *str = '%'; | ||
1691 | ++str; | ||
1692 | break; | ||
1693 | |||
1694 | case FORMAT_TYPE_INVALID: | 1738 | case FORMAT_TYPE_INVALID: |
1695 | if (str < end) | 1739 | if (str < end) |
1696 | *str = '%'; | 1740 | *str = '%'; |
@@ -1701,15 +1745,15 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1701 | /* skip */ | 1745 | /* skip */ |
1702 | break; | 1746 | break; |
1703 | 1747 | ||
1704 | default: | 1748 | default: { |
1749 | unsigned long long num; | ||
1750 | |||
1705 | switch (spec.type) { | 1751 | switch (spec.type) { |
1706 | 1752 | ||
1707 | case FORMAT_TYPE_LONG_LONG: | 1753 | case FORMAT_TYPE_LONG_LONG: |
1708 | num = get_arg(long long); | 1754 | num = get_arg(long long); |
1709 | break; | 1755 | break; |
1710 | case FORMAT_TYPE_ULONG: | 1756 | case FORMAT_TYPE_ULONG: |
1711 | num = get_arg(unsigned long); | ||
1712 | break; | ||
1713 | case FORMAT_TYPE_LONG: | 1757 | case FORMAT_TYPE_LONG: |
1714 | num = get_arg(unsigned long); | 1758 | num = get_arg(unsigned long); |
1715 | break; | 1759 | break; |
@@ -1739,8 +1783,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1739 | } | 1783 | } |
1740 | 1784 | ||
1741 | str = number(str, end, num, spec); | 1785 | str = number(str, end, num, spec); |
1742 | } | 1786 | } /* default: */ |
1743 | } | 1787 | } /* switch(spec.type) */ |
1788 | } /* while(*fmt) */ | ||
1744 | 1789 | ||
1745 | if (size > 0) { | 1790 | if (size > 0) { |
1746 | if (str < end) | 1791 | if (str < end) |
@@ -1774,6 +1819,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) | |||
1774 | va_start(args, fmt); | 1819 | va_start(args, fmt); |
1775 | ret = vbin_printf(bin_buf, size, fmt, args); | 1820 | ret = vbin_printf(bin_buf, size, fmt, args); |
1776 | va_end(args); | 1821 | va_end(args); |
1822 | |||
1777 | return ret; | 1823 | return ret; |
1778 | } | 1824 | } |
1779 | EXPORT_SYMBOL_GPL(bprintf); | 1825 | EXPORT_SYMBOL_GPL(bprintf); |
@@ -1786,27 +1832,23 @@ EXPORT_SYMBOL_GPL(bprintf); | |||
1786 | * @fmt: format of buffer | 1832 | * @fmt: format of buffer |
1787 | * @args: arguments | 1833 | * @args: arguments |
1788 | */ | 1834 | */ |
1789 | int vsscanf(const char * buf, const char * fmt, va_list args) | 1835 | int vsscanf(const char *buf, const char *fmt, va_list args) |
1790 | { | 1836 | { |
1791 | const char *str = buf; | 1837 | const char *str = buf; |
1792 | char *next; | 1838 | char *next; |
1793 | char digit; | 1839 | char digit; |
1794 | int num = 0; | 1840 | int num = 0; |
1795 | int qualifier; | 1841 | int qualifier, base, field_width; |
1796 | int base; | 1842 | bool is_sign; |
1797 | int field_width; | ||
1798 | int is_sign = 0; | ||
1799 | 1843 | ||
1800 | while(*fmt && *str) { | 1844 | while (*fmt && *str) { |
1801 | /* skip any white space in format */ | 1845 | /* skip any white space in format */ |
1802 | /* white space in format matchs any amount of | 1846 | /* white space in format matchs any amount of |
1803 | * white space, including none, in the input. | 1847 | * white space, including none, in the input. |
1804 | */ | 1848 | */ |
1805 | if (isspace(*fmt)) { | 1849 | if (isspace(*fmt)) { |
1806 | while (isspace(*fmt)) | 1850 | fmt = skip_spaces(++fmt); |
1807 | ++fmt; | 1851 | str = skip_spaces(str); |
1808 | while (isspace(*str)) | ||
1809 | ++str; | ||
1810 | } | 1852 | } |
1811 | 1853 | ||
1812 | /* anything that is not a conversion must match exactly */ | 1854 | /* anything that is not a conversion must match exactly */ |
@@ -1819,7 +1861,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1819 | if (!*fmt) | 1861 | if (!*fmt) |
1820 | break; | 1862 | break; |
1821 | ++fmt; | 1863 | ++fmt; |
1822 | 1864 | ||
1823 | /* skip this conversion. | 1865 | /* skip this conversion. |
1824 | * advance both strings to next white space | 1866 | * advance both strings to next white space |
1825 | */ | 1867 | */ |
@@ -1838,8 +1880,8 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1838 | 1880 | ||
1839 | /* get conversion qualifier */ | 1881 | /* get conversion qualifier */ |
1840 | qualifier = -1; | 1882 | qualifier = -1; |
1841 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1883 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
1842 | *fmt == 'Z' || *fmt == 'z') { | 1884 | TOLOWER(*fmt) == 'z') { |
1843 | qualifier = *fmt++; | 1885 | qualifier = *fmt++; |
1844 | if (unlikely(qualifier == *fmt)) { | 1886 | if (unlikely(qualifier == *fmt)) { |
1845 | if (qualifier == 'h') { | 1887 | if (qualifier == 'h') { |
@@ -1851,16 +1893,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1851 | } | 1893 | } |
1852 | } | 1894 | } |
1853 | } | 1895 | } |
1854 | base = 10; | ||
1855 | is_sign = 0; | ||
1856 | 1896 | ||
1857 | if (!*fmt || !*str) | 1897 | if (!*fmt || !*str) |
1858 | break; | 1898 | break; |
1859 | 1899 | ||
1860 | switch(*fmt++) { | 1900 | base = 10; |
1901 | is_sign = 0; | ||
1902 | |||
1903 | switch (*fmt++) { | ||
1861 | case 'c': | 1904 | case 'c': |
1862 | { | 1905 | { |
1863 | char *s = (char *) va_arg(args,char*); | 1906 | char *s = (char *)va_arg(args, char*); |
1864 | if (field_width == -1) | 1907 | if (field_width == -1) |
1865 | field_width = 1; | 1908 | field_width = 1; |
1866 | do { | 1909 | do { |
@@ -1871,17 +1914,15 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1871 | continue; | 1914 | continue; |
1872 | case 's': | 1915 | case 's': |
1873 | { | 1916 | { |
1874 | char *s = (char *) va_arg(args, char *); | 1917 | char *s = (char *)va_arg(args, char *); |
1875 | if(field_width == -1) | 1918 | if (field_width == -1) |
1876 | field_width = INT_MAX; | 1919 | field_width = INT_MAX; |
1877 | /* first, skip leading white space in buffer */ | 1920 | /* first, skip leading white space in buffer */ |
1878 | while (isspace(*str)) | 1921 | str = skip_spaces(str); |
1879 | str++; | ||
1880 | 1922 | ||
1881 | /* now copy until next white space */ | 1923 | /* now copy until next white space */ |
1882 | while (*str && !isspace(*str) && field_width--) { | 1924 | while (*str && !isspace(*str) && field_width--) |
1883 | *s++ = *str++; | 1925 | *s++ = *str++; |
1884 | } | ||
1885 | *s = '\0'; | 1926 | *s = '\0'; |
1886 | num++; | 1927 | num++; |
1887 | } | 1928 | } |
@@ -1889,7 +1930,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1889 | case 'n': | 1930 | case 'n': |
1890 | /* return number of characters read so far */ | 1931 | /* return number of characters read so far */ |
1891 | { | 1932 | { |
1892 | int *i = (int *)va_arg(args,int*); | 1933 | int *i = (int *)va_arg(args, int*); |
1893 | *i = str - buf; | 1934 | *i = str - buf; |
1894 | } | 1935 | } |
1895 | continue; | 1936 | continue; |
@@ -1901,14 +1942,14 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1901 | base = 16; | 1942 | base = 16; |
1902 | break; | 1943 | break; |
1903 | case 'i': | 1944 | case 'i': |
1904 | base = 0; | 1945 | base = 0; |
1905 | case 'd': | 1946 | case 'd': |
1906 | is_sign = 1; | 1947 | is_sign = 1; |
1907 | case 'u': | 1948 | case 'u': |
1908 | break; | 1949 | break; |
1909 | case '%': | 1950 | case '%': |
1910 | /* looking for '%' in str */ | 1951 | /* looking for '%' in str */ |
1911 | if (*str++ != '%') | 1952 | if (*str++ != '%') |
1912 | return num; | 1953 | return num; |
1913 | continue; | 1954 | continue; |
1914 | default: | 1955 | default: |
@@ -1919,71 +1960,70 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1919 | /* have some sort of integer conversion. | 1960 | /* have some sort of integer conversion. |
1920 | * first, skip white space in buffer. | 1961 | * first, skip white space in buffer. |
1921 | */ | 1962 | */ |
1922 | while (isspace(*str)) | 1963 | str = skip_spaces(str); |
1923 | str++; | ||
1924 | 1964 | ||
1925 | digit = *str; | 1965 | digit = *str; |
1926 | if (is_sign && digit == '-') | 1966 | if (is_sign && digit == '-') |
1927 | digit = *(str + 1); | 1967 | digit = *(str + 1); |
1928 | 1968 | ||
1929 | if (!digit | 1969 | if (!digit |
1930 | || (base == 16 && !isxdigit(digit)) | 1970 | || (base == 16 && !isxdigit(digit)) |
1931 | || (base == 10 && !isdigit(digit)) | 1971 | || (base == 10 && !isdigit(digit)) |
1932 | || (base == 8 && (!isdigit(digit) || digit > '7')) | 1972 | || (base == 8 && (!isdigit(digit) || digit > '7')) |
1933 | || (base == 0 && !isdigit(digit))) | 1973 | || (base == 0 && !isdigit(digit))) |
1934 | break; | 1974 | break; |
1935 | 1975 | ||
1936 | switch(qualifier) { | 1976 | switch (qualifier) { |
1937 | case 'H': /* that's 'hh' in format */ | 1977 | case 'H': /* that's 'hh' in format */ |
1938 | if (is_sign) { | 1978 | if (is_sign) { |
1939 | signed char *s = (signed char *) va_arg(args,signed char *); | 1979 | signed char *s = (signed char *)va_arg(args, signed char *); |
1940 | *s = (signed char) simple_strtol(str,&next,base); | 1980 | *s = (signed char)simple_strtol(str, &next, base); |
1941 | } else { | 1981 | } else { |
1942 | unsigned char *s = (unsigned char *) va_arg(args, unsigned char *); | 1982 | unsigned char *s = (unsigned char *)va_arg(args, unsigned char *); |
1943 | *s = (unsigned char) simple_strtoul(str, &next, base); | 1983 | *s = (unsigned char)simple_strtoul(str, &next, base); |
1944 | } | 1984 | } |
1945 | break; | 1985 | break; |
1946 | case 'h': | 1986 | case 'h': |
1947 | if (is_sign) { | 1987 | if (is_sign) { |
1948 | short *s = (short *) va_arg(args,short *); | 1988 | short *s = (short *)va_arg(args, short *); |
1949 | *s = (short) simple_strtol(str,&next,base); | 1989 | *s = (short)simple_strtol(str, &next, base); |
1950 | } else { | 1990 | } else { |
1951 | unsigned short *s = (unsigned short *) va_arg(args, unsigned short *); | 1991 | unsigned short *s = (unsigned short *)va_arg(args, unsigned short *); |
1952 | *s = (unsigned short) simple_strtoul(str, &next, base); | 1992 | *s = (unsigned short)simple_strtoul(str, &next, base); |
1953 | } | 1993 | } |
1954 | break; | 1994 | break; |
1955 | case 'l': | 1995 | case 'l': |
1956 | if (is_sign) { | 1996 | if (is_sign) { |
1957 | long *l = (long *) va_arg(args,long *); | 1997 | long *l = (long *)va_arg(args, long *); |
1958 | *l = simple_strtol(str,&next,base); | 1998 | *l = simple_strtol(str, &next, base); |
1959 | } else { | 1999 | } else { |
1960 | unsigned long *l = (unsigned long*) va_arg(args,unsigned long*); | 2000 | unsigned long *l = (unsigned long *)va_arg(args, unsigned long *); |
1961 | *l = simple_strtoul(str,&next,base); | 2001 | *l = simple_strtoul(str, &next, base); |
1962 | } | 2002 | } |
1963 | break; | 2003 | break; |
1964 | case 'L': | 2004 | case 'L': |
1965 | if (is_sign) { | 2005 | if (is_sign) { |
1966 | long long *l = (long long*) va_arg(args,long long *); | 2006 | long long *l = (long long *)va_arg(args, long long *); |
1967 | *l = simple_strtoll(str,&next,base); | 2007 | *l = simple_strtoll(str, &next, base); |
1968 | } else { | 2008 | } else { |
1969 | unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*); | 2009 | unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *); |
1970 | *l = simple_strtoull(str,&next,base); | 2010 | *l = simple_strtoull(str, &next, base); |
1971 | } | 2011 | } |
1972 | break; | 2012 | break; |
1973 | case 'Z': | 2013 | case 'Z': |
1974 | case 'z': | 2014 | case 'z': |
1975 | { | 2015 | { |
1976 | size_t *s = (size_t*) va_arg(args,size_t*); | 2016 | size_t *s = (size_t *)va_arg(args, size_t *); |
1977 | *s = (size_t) simple_strtoul(str,&next,base); | 2017 | *s = (size_t)simple_strtoul(str, &next, base); |
1978 | } | 2018 | } |
1979 | break; | 2019 | break; |
1980 | default: | 2020 | default: |
1981 | if (is_sign) { | 2021 | if (is_sign) { |
1982 | int *i = (int *) va_arg(args, int*); | 2022 | int *i = (int *)va_arg(args, int *); |
1983 | *i = (int) simple_strtol(str,&next,base); | 2023 | *i = (int)simple_strtol(str, &next, base); |
1984 | } else { | 2024 | } else { |
1985 | unsigned int *i = (unsigned int*) va_arg(args, unsigned int*); | 2025 | unsigned int *i = (unsigned int *)va_arg(args, unsigned int*); |
1986 | *i = (unsigned int) simple_strtoul(str,&next,base); | 2026 | *i = (unsigned int)simple_strtoul(str, &next, base); |
1987 | } | 2027 | } |
1988 | break; | 2028 | break; |
1989 | } | 2029 | } |
@@ -2014,14 +2054,15 @@ EXPORT_SYMBOL(vsscanf); | |||
2014 | * @fmt: formatting of buffer | 2054 | * @fmt: formatting of buffer |
2015 | * @...: resulting arguments | 2055 | * @...: resulting arguments |
2016 | */ | 2056 | */ |
2017 | int sscanf(const char * buf, const char * fmt, ...) | 2057 | int sscanf(const char *buf, const char *fmt, ...) |
2018 | { | 2058 | { |
2019 | va_list args; | 2059 | va_list args; |
2020 | int i; | 2060 | int i; |
2021 | 2061 | ||
2022 | va_start(args,fmt); | 2062 | va_start(args, fmt); |
2023 | i = vsscanf(buf,fmt,args); | 2063 | i = vsscanf(buf, fmt, args); |
2024 | va_end(args); | 2064 | va_end(args); |
2065 | |||
2025 | return i; | 2066 | return i; |
2026 | } | 2067 | } |
2027 | EXPORT_SYMBOL(sscanf); | 2068 | EXPORT_SYMBOL(sscanf); |