Reputation: 728
While developing my FreeRTOS application targeting an ARM Cortex M3 with GCC, using the C99 dialect, I decided to use strnlen, assuming that it's a standard C function and that I just need to include to use it. The compiler warns me of an implicit declaration for strnlen, making me realize it's not part of the C99 standard. However, since there hasn't been any linker errors, I assume the function does exist somewhere..
What header am I supposed to include in order to use strnlen, if it's not string.h? Most websites online and the man page for strnlen mention including string.h as the header
Upvotes: 0
Views: 459
Reputation: 1414
Just implement it yourself, without a particular header.
size_t strnlen(const char *s, size_t maxlen) {
size_t len = 0;
if(s)
for(char c = *s; (len < maxlen && c != '\0'); c = *++s) len++;
return len;
}
Upvotes: 3