fxlibc/src/string/strlen.c

38 lines
821 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <fxlibc/string.h>
/*
** The strlen() function calculates the length of the string pointed to by s,
** excluding the terminating 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);
}