I understand your question is multi-layered, and the run-time crashing of your custom strlen() is nearly a side note, but I thought I'd address just this one aspect nonetheless. Does your code care for the possibility of a NULL parameter as does the following custom strlen()?
Runnable code here: https://godbolt.org/z/xofh9sYqK
#include <stdio.h> /* printf() */
size_t mstrlen( const char *str )
{
size_t len = 0;
if( str ) /* Prevent run-time crash on NULL pointer. */
{
for(; str[len]; len++);
}
return len;
}
int main()
{
char s[] = "stars";
printf("mstrlen(%s) = %llu\n", s, mstrlen(s));
printf("mstrlen(NULL) = %llu\n", mstrlen(NULL));
return 0;
}