From owner-freebsd-hackers Thu Jul 15 16: 4:40 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from alpo.whistle.com (alpo.whistle.com [207.76.204.38]) by hub.freebsd.org (Postfix) with ESMTP id 39FE41562F for ; Thu, 15 Jul 1999 16:04:34 -0700 (PDT) (envelope-from julian@whistle.com) Received: from current1.whistle.com (current1.whistle.com [207.76.205.22]) by alpo.whistle.com (8.9.1a/8.9.1) with SMTP id QAA04599; Thu, 15 Jul 1999 16:04:13 -0700 (PDT) Date: Thu, 15 Jul 1999 16:04:12 -0700 (PDT) From: Julian Elischer To: Mike Smith Cc: Tim Vanderhoek , Sheldon Hearn , Garance A Drosihn , Paul Hart , freebsd-hackers@FreeBSD.ORG Subject: Re: OpenBSD's strlcpy(3) and strlcat(3) In-Reply-To: <199907152244.PAA01458@dingo.cdrom.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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