Provide g_strnlen
Submitted by Behdad Esfahbod
Link to original bug (#332672)
Description
strnlen is a GNU extension. It is useful to figure out what's the length of the string that functions like g_utf8_strlen (that take a max_len) will use...
Something like:
int g_strnlen (const char* str, int len) { if (max_len < 0) return = strlen(str); else if (max_len > 0) { const char *end;
end = memchr(str, 0, maxlen);
if (end)
return end - str;
else
return maxlen;
}
else return 0; }