a C standard library for fx Casio calculators
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
fxlibc/src/libc/string/strlen.c

37 lines
814 B

#include <string.h>
/*
** The strlen() function calculates the length of the string pointed to by s,
** excluding the termi‐nating null byte ('\0').
**
** TODO: use quad-word access !
*/
size_t strlen(char const *str)
{
size_t i;
if (str == NULL)
return (0);
i = -1;
while (str[++i] != '\0') ;
return (i);
}
/*
** The strnlen() function returns the number of bytes in the string pointed to
** by s, excluding the terminating null byte ('\0'), but at most maxlen.
** In doing this, strnlen() looks only at the first maxlen characters in the
** string pointed to by s and never beyond s+maxlen.
**
** TODO: use quad-word access !
*/
size_t strnlen(char const *str, size_t maxlen)
{
size_t i;
if (str == NULL)
return (0);
i = -1;
while (str[++i] != '\0' && (size_t)i < maxlen) ;
return (i);
}