X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2Fstring.c;h=bab440fb0dfcb99dfe46453350f7b6e9298c89eb;hb=1ad5b4a5c224c5f98f9745adbcf99899624c8138;hp=064f6315b1c3e16c731117a7e1aa185a5b2bd405;hpb=35a5d9ed9fedb74c22cb19ff7d749289473144e0;p=powerpc.git diff --git a/lib/string.c b/lib/string.c index 064f6315b1..bab440fb0d 100644 --- a/lib/string.c +++ b/lib/string.c @@ -160,7 +160,7 @@ EXPORT_SYMBOL(strcat); * @src: The string to append to it * @count: The maximum numbers of bytes to copy * - * Note that in contrast to strncpy, strncat ensures the result is + * Note that in contrast to strncpy(), strncat() ensures the result is * terminated. */ char *strncat(char *dest, const char *src, size_t count) @@ -301,6 +301,36 @@ char *strnchr(const char *s, size_t count, int c) EXPORT_SYMBOL(strnchr); #endif +/** + * strstrip - Removes leading and trailing whitespace from @s. + * @s: The string to be stripped. + * + * Note that the first trailing whitespace is replaced with a %NUL-terminator + * in the given string @s. Returns a pointer to the first non-whitespace + * character in @s. + */ +char *strstrip(char *s) +{ + size_t size; + char *end; + + size = strlen(s); + + if (!size) + return s; + + end = s + size - 1; + while (end >= s && isspace(*end)) + end--; + *(end + 1) = '\0'; + + while (*s && isspace(*s)) + s++; + + return s; +} +EXPORT_SYMBOL(strstrip); + #ifndef __HAVE_ARCH_STRLEN /** * strlen - Find the length of a string @@ -336,8 +366,7 @@ EXPORT_SYMBOL(strnlen); #ifndef __HAVE_ARCH_STRSPN /** - * strspn - Calculate the length of the initial substring of @s which only - * contain letters in @accept + * strspn - Calculate the length of the initial substring of @s which only contain letters in @accept * @s: The string to be searched * @accept: The string to search for */ @@ -364,8 +393,7 @@ EXPORT_SYMBOL(strspn); #ifndef __HAVE_ARCH_STRCSPN /** - * strcspn - Calculate the length of the initial substring of @s which does - * not contain letters in @reject + * strcspn - Calculate the length of the initial substring of @s which does not contain letters in @reject * @s: The string to be searched * @reject: The string to avoid */