aboutsummaryrefslogtreecommitdiffstats
path: root/lib/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c25
1 files changed, 18 insertions, 7 deletions
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 */
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.
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 */
348char *strstrip(char *s) 362char *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}
368EXPORT_SYMBOL(strstrip); 379EXPORT_SYMBOL(strim);
369 380
370#ifndef __HAVE_ARCH_STRLEN 381#ifndef __HAVE_ARCH_STRLEN
371/** 382/**