There is a strnlen()
function which has been added for some time to various high-profile libraries, and subsequently made its way into standards like POSIX-1:2008. IIUC its purpose is to avoid problems when the subject string is not nul-terminated.
However, I do not see the similar variants strnspn()
or strncspn()
to have been developed, despite that similar potential problems might be alleged. Is it just because the base strspn()
and strcspn()
are beyond the understanding of many C programmers, hence supposed to be unused or unusable?
One may notice that in the (in)famous "security-enhanced" (a.k.a. annex-K or M's-extension) variants of the string functions , there are no strcspn_s()
nor strspn_s()
either...