On 08/08/10 17:41, Pádraig Brady wrote:
> Are there other reasons for not using strnlen()
> apart from it not dealing with NULs in the input?

Generally speaking, a data structure where
strnlen makes sense is a data structure that
is probably poorly designed.  strnlen was
originally designed for the likes of Unix
Version 7 directory entries, which had 14
bytes for the name and 2 bytes for the inode
number, where names were limited to 14 bytes
in length, and where they didn't want to insist
on null-terminated names (and therefore limit
the name length to 13 bytes, to keep inode sizes
a power of two).

GNU code is not supposed to have silly limits like
that, and unless it's dealing with externally-designed
data structures that resemble V7 inode entries, it
shouldn't need strnlen.

Also, strnlen is confusing.

strncpy is even worse.  Don't get me started on strncpy!

Reply via email to