No subject
Thu Mar 29 20:50:10 PDT 2007
------------------------
SYNOPSIS
#include <string.h>
size_t strnlen(const char *s, size_t maxlen);
DESCRIPTION
The strnlen function returns the number of characters in the string
pointed to by s, not including the terminating '\0' character, but at
most maxlen. In doing this, strnlen looks only at the first maxlen
characters at s and never beyond s+maxlen.
RETURN VALUE
The strnlen function returns strlen(s), if that is less than maxlen, or
maxlen if there is no '\0' character among the first maxlen characters
pointed to by s.
CONFORMING TO
This function is a GNU extension.
-----------
And here is a simple implementation:
ulong strnlen(char* s, ulong maxlen){
for(ulong i=0; i<maxlen; ++i){
if (!s[i]) return i;
}
return maxlen;
}
[I used ulong, since a UNIX string could be an entire file.]
--
More information about the Digitalmars-d-bugs
mailing list