X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fstring.c;h=a485d75962af5f7a6bbb4f819aa780c812fe25ca;hb=a2f44b27303a5353859d77a3e96a1d3f33f56ab7;hp=037a48acedbb21aae00269c87ef9f1821fb1bb67;hpb=134734d875a0a48d994ef20b9905209b4b8b6f75;p=linux-2.6.git diff --git a/lib/string.c b/lib/string.c index 037a48ace..a485d7596 100644 --- a/lib/string.c +++ b/lib/string.c @@ -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 @@ -362,6 +392,7 @@ size_t strspn(const char *s, const char *accept) EXPORT_SYMBOL(strspn); #endif +#ifndef __HAVE_ARCH_STRCSPN /** * strcspn - Calculate the length of the initial substring of @s which does * not contain letters in @reject @@ -384,6 +415,7 @@ size_t strcspn(const char *s, const char *reject) return count; } EXPORT_SYMBOL(strcspn); +#endif #ifndef __HAVE_ARCH_STRPBRK /** @@ -468,7 +500,7 @@ EXPORT_SYMBOL(memset); void *memcpy(void *dest, const void *src, size_t count) { char *tmp = dest; - char *s = src; + const char *s = src; while (count--) *tmp++ = *s++;