From: des Date: Tue, 22 Aug 2006 09:31:34 +0000 (+0000) Subject: Slight optimization: use strlcpy() to avoid calloc(). X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab9eeae898178df15b4d12a51fde4b1676e79773;p=varnish Slight optimization: use strlcpy() to avoid calloc(). git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@891 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libcompat/strndup.c b/varnish-cache/lib/libcompat/strndup.c index a88493af..0f7b36f2 100644 --- a/varnish-cache/lib/libcompat/strndup.c +++ b/varnish-cache/lib/libcompat/strndup.c @@ -8,6 +8,10 @@ #include #include +#ifndef HAVE_STRLCPY +#include "compat/strlcpy.h" +#endif + #include "compat/strndup.h" char * @@ -16,8 +20,8 @@ strndup(const char *str, size_t len) char *dup; /* wasteful if len is large and str is short */ - if ((dup = calloc(len + 1, 1)) != NULL) - strncpy(dup, str, len); + if ((dup = malloc(len + 1)) != NULL) + strlcpy(dup, str, len + 1); return (dup); }