aboutsummaryrefslogtreecommitdiffstats
path: root/lib/string.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2010-01-04 19:17:33 -0500
committerTejun Heo <tj@kernel.org>2010-01-04 19:17:33 -0500
commit32032df6c2f6c9c6b2ada2ce42322231824f70c2 (patch)
treeb1ce838a37044bb38dfc128e2116ca35630e629a /lib/string.c
parent22b737f4c75197372d64afc6ed1bccd58c00e549 (diff)
parentc5974b835a909ff15c3b7e6cf6789b5eb919f419 (diff)
Merge branch 'master' into percpu
Conflicts: arch/powerpc/platforms/pseries/hvCall.S include/linux/percpu.h
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/string.c b/lib/string.c
index b19b87af65a3..9f75b4ec50b8 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -246,13 +246,17 @@ EXPORT_SYMBOL(strlcat);
246#undef strcmp 246#undef strcmp
247int strcmp(const char *cs, const char *ct) 247int strcmp(const char *cs, const char *ct)
248{ 248{
249 signed char __res; 249 unsigned char c1, c2;
250 250
251 while (1) { 251 while (1) {
252 if ((__res = *cs - *ct++) != 0 || !*cs++) 252 c1 = *cs++;
253 c2 = *ct++;
254 if (c1 != c2)
255 return c1 < c2 ? -1 : 1;
256 if (!c1)
253 break; 257 break;
254 } 258 }
255 return __res; 259 return 0;
256} 260}
257EXPORT_SYMBOL(strcmp); 261EXPORT_SYMBOL(strcmp);
258#endif 262#endif
@@ -266,14 +270,18 @@ EXPORT_SYMBOL(strcmp);
266 */ 270 */
267int strncmp(const char *cs, const char *ct, size_t count) 271int strncmp(const char *cs, const char *ct, size_t count)
268{ 272{
269 signed char __res = 0; 273 unsigned char c1, c2;
270 274
271 while (count) { 275 while (count) {
272 if ((__res = *cs - *ct++) != 0 || !*cs++) 276 c1 = *cs++;
277 c2 = *ct++;
278 if (c1 != c2)
279 return c1 < c2 ? -1 : 1;
280 if (!c1)
273 break; 281 break;
274 count--; 282 count--;
275 } 283 }
276 return __res; 284 return 0;
277} 285}
278EXPORT_SYMBOL(strncmp); 286EXPORT_SYMBOL(strncmp);
279#endif 287#endif
@@ -330,20 +338,34 @@ EXPORT_SYMBOL(strnchr);
330#endif 338#endif
331 339
332/** 340/**
333 * strstrip - Removes leading and trailing whitespace from @s. 341 * skip_spaces - Removes leading whitespace from @str.
342 * @str: The string to be stripped.
343 *
344 * Returns a pointer to the first non-whitespace character in @str.
345 */
346char *skip_spaces(const char *str)
347{
348 while (isspace(*str))
349 ++str;
350 return (char *)str;
351}
352EXPORT_SYMBOL(skip_spaces);
353
354/**
355 * strim - Removes leading and trailing whitespace from @s.
334 * @s: The string to be stripped. 356 * @s: The string to be stripped.
335 * 357 *
336 * 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
337 * 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
338 * character in @s. 360 * character in @s.
339 */ 361 */
340char *strstrip(char *s) 362char *strim(char *s)
341{ 363{
342 size_t size; 364 size_t size;
343 char *end; 365 char *end;
344 366
367 s = skip_spaces(s);
345 size = strlen(s); 368 size = strlen(s);
346
347 if (!size) 369 if (!size)
348 return s; 370 return s;
349 371
@@ -352,12 +374,9 @@ char *strstrip(char *s)
352 end--; 374 end--;
353 *(end + 1) = '\0'; 375 *(end + 1) = '\0';
354 376
355 while (*s && isspace(*s))
356 s++;
357
358 return s; 377 return s;
359} 378}
360EXPORT_SYMBOL(strstrip); 379EXPORT_SYMBOL(strim);
361 380
362#ifndef __HAVE_ARCH_STRLEN 381#ifndef __HAVE_ARCH_STRLEN
363/** 382/**