diff options
Diffstat (limited to 'lib/string.c')
-rw-r--r-- | lib/string.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/string.c b/lib/string.c index 6016eb3ac73d..461fb620f85f 100644 --- a/lib/string.c +++ b/lib/string.c | |||
@@ -400,6 +400,9 @@ EXPORT_SYMBOL(strncmp); | |||
400 | * strchr - Find the first occurrence of a character in a string | 400 | * strchr - Find the first occurrence of a character in a string |
401 | * @s: The string to be searched | 401 | * @s: The string to be searched |
402 | * @c: The character to search for | 402 | * @c: The character to search for |
403 | * | ||
404 | * Note that the %NUL-terminator is considered part of the string, and can | ||
405 | * be searched for. | ||
403 | */ | 406 | */ |
404 | char *strchr(const char *s, int c) | 407 | char *strchr(const char *s, int c) |
405 | { | 408 | { |
@@ -453,12 +456,18 @@ EXPORT_SYMBOL(strrchr); | |||
453 | * @s: The string to be searched | 456 | * @s: The string to be searched |
454 | * @count: The number of characters to be searched | 457 | * @count: The number of characters to be searched |
455 | * @c: The character to search for | 458 | * @c: The character to search for |
459 | * | ||
460 | * Note that the %NUL-terminator is considered part of the string, and can | ||
461 | * be searched for. | ||
456 | */ | 462 | */ |
457 | char *strnchr(const char *s, size_t count, int c) | 463 | char *strnchr(const char *s, size_t count, int c) |
458 | { | 464 | { |
459 | for (; count-- && *s != '\0'; ++s) | 465 | while (count--) { |
460 | if (*s == (char)c) | 466 | if (*s == (char)c) |
461 | return (char *)s; | 467 | return (char *)s; |
468 | if (*s++ == '\0') | ||
469 | break; | ||
470 | } | ||
462 | return NULL; | 471 | return NULL; |
463 | } | 472 | } |
464 | EXPORT_SYMBOL(strnchr); | 473 | EXPORT_SYMBOL(strnchr); |