Date: 18 Dec 2000 15:40:25 +0100 From: Dag-Erling Smorgrav <des@ofug.org> To: Assar Westerlund <assar@FreeBSD.org> 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 Message-ID: <xzpae9tztba.fsf@flood.ping.uio.no> In-Reply-To: Dag-Erling Smorgrav's message of "18 Dec 2000 15:23:43 %2B0100" References: <200012180408.eBI48wg99879@freefall.freebsd.org> <xzpu282ypvp.fsf@flood.ping.uio.no> <5l66khluty.fsf@assaris.sics.se> <xzpitohzu34.fsf@flood.ping.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-= Dag-Erling Smorgrav <des@ofug.org> writes: > Assar Westerlund <assar@FreeBSD.org> 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 <string.h> 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 <string.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpae9tztba.fsf>