ape: add strnlen

This commit is contained in:
spew 2018-06-21 11:56:37 -04:00
parent 3b376b43af
commit 55c122d59f
4 changed files with 13 additions and 1 deletions

View file

@ -32,6 +32,7 @@ extern char *strtok(char *, const char *);
extern void *memset(void *, int, size_t);
extern char *strerror(int);
extern size_t strlen(const char *);
extern size_t strnlen(const char *, size_t);
#ifdef _REENTRANT_SOURCE
extern char *strerror_r(int, const char *, int);

View file

@ -43,6 +43,7 @@ ALLOFILES=\
strncat.$O\
strncmp.$O\
strncpy.$O\
strnlen.$O\
strpbrk.$O\
strrchr.$O\
strspn.$O\

View file

@ -3,6 +3,5 @@
size_t
strlen(const char *s)
{
return strchr(s, 0) - s;
}

View file

@ -0,0 +1,11 @@
#include <string.h>
size_t
strnlen(const char *s, size_t maxlen)
{
size_t i;
for (i = 0; i < maxlen && s[i] != '\0'; i++)
;
return i;
}