Need strnlen().

jack at boring.UUCP jack at boring.UUCP
Sat Nov 16 11:13:55 AEST 1985


In article <207 at a.sei.cmu.edu> dlc at a.sei.cmu.edu (Daryl Clevenger) writes:
>One should never allow a character array to not have a null terminating byte.
That's right, one *should* never allow it. On the other hand,
if ou look at the format of /etc/utmp (v7, at least, dunno about
4.n or S5), there's 8 bytes available for loginnames, so if
you've got an 8 char loginname, it won't be zero terminated.

Or, look at the V7 directory entry for a 14-char filename.

I *know* these should be avoided, but I would still prefer to see
code like
	len = strnlen(buffer,BUFSIZ);
above
	if( (len=strlen(buffer))>BUFSIZ) len=BUFSIZ;
which will fail at some unknown point in the future, long
after everyone who knew the code has passed away.......
-- 
	Jack Jansen, jack at mcvax.UUCP
	The shell is my oyster.



More information about the Comp.lang.c mailing list