Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 May 2001 18:22:04 +0300
From:      Valentin Nechayev <netch@iv.nn.kiev.ua>
To:        roam@orbitel.bg
Cc:        Daniel Hemmerich <dan@BSDpro.com>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: adding a new function to libc
Message-ID:  <20010512182203.A297@iv.nn.kiev.ua>
In-Reply-To: <20010512171240.A54542@ringworld.oblivion.bg>; from roam@orbitel.bg on Sat, May 12, 2001 at 05:12:41PM %2B0300
References:  <01051202104500.95296@blackhole.BSDpro.com> <20010512170544.A343@iv.nn.kiev.ua> <20010512171240.A54542@ringworld.oblivion.bg>

next in thread | previous in thread | raw e-mail | index | archive | help
 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 majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010512182203.A297>