1
0

strlen(3) strnlen(3)

This commit is contained in:
dtb 2022-09-18 10:53:17 -04:00
parent fd8f2bee3e
commit 4206d6dee5
2 changed files with 22 additions and 0 deletions

17
cstdlib/string.c Normal file
View File

@ -0,0 +1,17 @@
size_t
strlen(const char *s){
size_t r;
for(r = 0; s[r] != '\0'; ++r);
return r;
}
size_t
strnlen(const char *s, size_t maxlen){
size_t r;
for(r = 0; s[r] != '\0' && r < maxlen; ++r);
return r;
}

5
cstdlib/string.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef _STRING_H
# define _STRING_H
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t maxlen);
#endif /* ifndef _STRING_H */