Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/string/strnlen.c
Show All 26 Lines | ||||||||||
*/ | */ | |||||||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | |||||||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | |||||||||
#include <string.h> | #include <string.h> | |||||||||
size_t | size_t | |||||||||
strnlen(const char *s, size_t maxlen) | strnlen(const char *ptr, size_t maxlen) | |||||||||
{ | { | |||||||||
size_t len; | const char *r; | |||||||||
for (len = 0; len < maxlen; len++, s++) { | r = memchr(ptr, '\0', maxlen); | |||||||||
if (!*s) | ||||||||||
break; | if (r == NULL) | |||||||||
} | return maxlen; | |||||||||
brooksUnsubmitted Done Inline Actions
brooks: | ||||||||||
return (len); | ||||||||||
return r - ptr; | ||||||||||
Done Inline ActionsI think '\0' is pretty typical emaste: I think `'\0'` is pretty typical | ||||||||||
Done Inline Actions
brooks: | ||||||||||
} | } |