Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Jul 1999 16:04:12 -0700 (PDT)
From:      Julian Elischer <julian@whistle.com>
To:        Mike Smith <mike@smith.net.au>
Cc:        Tim Vanderhoek <vanderh@ecf.utoronto.ca>, Sheldon Hearn <sheldonh@uunet.co.za>, Garance A Drosihn <drosih@rpi.edu>, Paul Hart <hart@iserver.com>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: OpenBSD's strlcpy(3) and strlcat(3) 
Message-ID:  <Pine.BSF.3.95.990715155513.6348C-100000@current1.whistle.com>
In-Reply-To: <199907152244.PAA01458@dingo.cdrom.com>

next in thread | previous in thread | raw e-mail | index | archive | help


On Thu, 15 Jul 1999, Mike Smith wrote:
> 

> What's really stupid is that most of the time you're trying to use 
> these functions to fix code that looks like:
> 
> 	strcpy(buf, str1);
> 	strcat(buf, str2);
> 	strcat(buf, str3);
> without overflowing buf.  This is dumb!  Use asprintf instead:

There was a talk on these (strlcpy(3) and strlcat(3)) at USENIX.
The logic as to their design was presented and I agree totally with 
the way that the logic was played out into the functions.

They are described in the FreeNIX proceedings on page 175.
I feel they make a lot more sense that teh present version sand we should
support OpenBSD's application to Posix to make them standard.

They lead to faster overall code, (people using present
functions often re-count the size of result strings, or check the end of
the buffer for a 0) and lead to more readable code.
All of these age a "Good Thing" (TM).


> 
> 	asprinf(&buf, "%s%s%s", str1, str2, str3);
>

Very nice but not always applicable. Particularly when compiling 
strings under algorythmic control.
 
> If you can't keep all of the string elements together at once, try:
> 
> 	asprinf(&buf, "%s%s", str1, str2);
> 	...
> 	asprintf(&buf2, "%s%s", buf, str3);
> 	free(buf);
> 
> No, it's not fast, but it _is_ robust.

Why not be fast AND robust?
:-)

I like the new functions and would like to see them supported.

julian




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?Pine.BSF.3.95.990715155513.6348C-100000>