Sat, May 12, 2001 at 17:12:41, roam (Peter Pentchev) wrote about "Re: adding a new 
function to libc": 

> > /* This is candidate to have optimized assembler variant */
> > size_t strnlen( const char* src, size_t max )
> > {
> >     size_t n;
> >     while( n < max && *src != '\0' )
> >             n++;
> >     return n;
> > }
> 
> I really hope you meant *src++ there :)

Yes, sorry. I incorrectly hoped to write it again from brain instead of
copying from sources.;|

Variant from my sources:

size_t strnlen( const char* src, size_t maxlen )
{
   register size_t len = 0;
   while( len < maxlen && src[len] )
      len++;
   return len;
}

Variant from linux kernel:

#ifndef __HAVE_ARCH_STRNLEN
size_t strnlen(const char * s, size_t count)
{
        const char *sc;

        for (sc = s; count-- && *sc != '\0'; ++sc)
                /* nothing */;
        return sc - s;
}
#endif


/netch

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to