Richard L. Hamilton writes:
> Jörg wrote:
> > I believe that strnlen is something like:
> >
> > p2 = memchr(p, o, len);
> > if (p == 0 || p2 - p > len)
> > return (len);
> > return (p2 - p);
> >
> > Why do you like to start with strlen()?
>
> What you posted resembles (although is not identical to) an LGPL
> implementation*, and
> str*() functions don't typically need to check for a NULL pointer (p == 0).
> I wanted to be
I'm not sure that answer is right. memchr() is _defined_ to return
NULL when the searched-for character is not present, so I assume the
first term of that if test should be "p2 == NULL".
Plus, the memchr itself won't work (except for very small values of
'o') and the second clause of that boolean test looks like nonsense to
me (as it simply cannot happen).
This looks closer to me:
p2 = memchr(p, 0, len);
return (p2 == NULL ? len : p2 - p);
And, no, I haven't looked at any of the GNU examples. I don't care
to. ;-}
--
James Carlson, KISS Network <[EMAIL PROTECTED]>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code