From owner-cvs-all Mon Dec 18 6:40:34 2000 From owner-cvs-all@FreeBSD.ORG Mon Dec 18 06:40:28 2000 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by hub.freebsd.org (Postfix) with ESMTP id 1A34337B400; Mon, 18 Dec 2000 06:40:27 -0800 (PST) Received: (from des@localhost) by flood.ping.uio.no (8.9.3/8.9.3) id PAA96661; Mon, 18 Dec 2000 15:40:26 +0100 (CET) (envelope-from des@ofug.org) Sender: des@ofug.org X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: Assar Westerlund Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/libkern strlcat.c strlcpy.c src/sys/sys libkern.h src/sys/conf files References: <200012180408.eBI48wg99879@freefall.freebsd.org> <5l66khluty.fsf@assaris.sics.se> From: Dag-Erling Smorgrav Date: 18 Dec 2000 15:40:25 +0100 In-Reply-To: Dag-Erling Smorgrav's message of "18 Dec 2000 15:23:43 +0100" Message-ID: Lines: 17 User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.4 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --=-=-= Dag-Erling Smorgrav writes: > Assar Westerlund writes: > > Is that really something worth optimizing? > Rewriting strcat() into strlcat() requires changing two lines, not > adding twenty. Slightly more than that, because the code is in K&R style, but you get the idea. Here's a rough untested patch (I didn't touch the headers; if you add the appropriate declarations to the header you can reduce the diff by moving strcat()/strcpy() ahead of strlcat()/strlcpy()). DES -- Dag-Erling Smorgrav - des@ofug.org --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=strl.diff Content-Description: strlcpy()/strlcat() patch Index: strcat.c =================================================================== RCS file: /home/ncvs/src/sys/libkern/strcat.c,v retrieving revision 1.6 diff -u -r1.6 strcat.c --- strcat.c 1999/08/28 00:46:37 1.6 +++ strcat.c 2000/12/18 14:31:05 @@ -36,13 +36,23 @@ #include char * -strcat(s, append) +strlcat(s, append, size) register char *s; register const char *append; + register size_t size; { char *save = s; - for (; *s; ++s); - while ((*s++ = *append++) != 0); + for (; --size && *s; ++s); + while (--size && (*s++ = *append++) != 0); + *s = 0; return(save); +} + +char * +strcat(s, append) + register char *s; + register const char *append; +{ + return strlcat(s, append, UINT_MAX); } Index: strcpy.c =================================================================== RCS file: /home/ncvs/src/sys/libkern/strcpy.c,v retrieving revision 1.7 diff -u -r1.7 strcpy.c --- strcpy.c 1999/08/28 00:46:37 1.7 +++ strcpy.c 2000/12/18 14:31:16 @@ -36,12 +36,22 @@ #include char * -strcpy(to, from) +strlcpy(to, from, size) register char *to; register const char *from; + register size_t size; { char *save = to; - for (; (*to = *from) != 0; ++from, ++to); + for (; --size && (*to = *from) != 0; ++from, ++to); + *to = 0; return(save); +} + +char * +strcpy(to, from) + register char *to; + register const char *from; +{ + return strlcpy(to, from, UINT_MAX); } --=-=-=-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message