Mailing List Archive

Strlcpy and strlcat
lib/str.c contains strlcpy and strlcat "implementations". I'd like to
have real implementations there to use strlcpy mostly. It affects
only Linux AFAIK, *BSD, Solaris, HP-UX etc. have these functions.

http://sources.redhat.com/ml/libc-alpha/2002-01/msg00002.html

Problem for me is where to get implementations. I know, BSD licence
without advertising clause is compatible with GPL etc., but AFAIK we
just can't say that Quagga is completely GPL then any more. That's
why many projects have their own implementations (Linux kernel, KDE
etc). So I'd better borrow implementations from kernel, but would
like to know opinions from others.


--
Hasso Tepper
Elion Enterprises Ltd.
WAN administrator
Re: Strlcpy and strlcat [ In reply to ]
On Tue, Jun 22, 2004 at 09:18:08AM +0300, Hasso Tepper wrote:
> lib/str.c contains strlcpy and strlcat "implementations". I'd like to
> have real implementations there to use strlcpy mostly. It affects
> only Linux AFAIK, *BSD, Solaris, HP-UX etc. have these functions.
>
> http://sources.redhat.com/ml/libc-alpha/2002-01/msg00002.html
>
> Problem for me is where to get implementations. I know, BSD licence

size_t
strlcpy(char *dst, const char *src0, size_t size)
{
const char *src;
for (src = src0; *src != '\0' && size > 1; size--)
*dst++ = *src++;
if (size >= 1)
*dst = '\0';
while (*src++ != '\0');
return src - src0;
}

size_t
strlcat(char *dst0, const char *src, size_t size)
{
char *dst;

for (dst = dst0; *dst != '\0' && size >= 1; size--)
dst++;
if (size >= 1)
return (dst - dst0) + strlcpy(dst, src, size);
return dst - dst0;
}

These are original implementations right off the top of my head.
Test them? You may put them under two-clause BSD license or GPLv2,
whichever you prefer.

Dave

--
David Young OJC Technologies
dyoung@ojctech.com Urbana, IL * (217) 278-3933