Mailing List Archive

r891 - trunk/varnish-cache/lib/libcompat
Author: des
Date: 2006-08-22 11:31:34 +0200 (Tue, 22 Aug 2006)
New Revision: 891

Modified:
trunk/varnish-cache/lib/libcompat/strndup.c
Log:
Slight optimization: use strlcpy() to avoid calloc().

Modified: trunk/varnish-cache/lib/libcompat/strndup.c
===================================================================
--- trunk/varnish-cache/lib/libcompat/strndup.c 2006-08-22 09:30:23 UTC (rev 890)
+++ trunk/varnish-cache/lib/libcompat/strndup.c 2006-08-22 09:31:34 UTC (rev 891)
@@ -8,6 +8,10 @@
#include <stdlib.h>
#include <string.h>

+#ifndef HAVE_STRLCPY
+#include "compat/strlcpy.h"
+#endif
+
#include "compat/strndup.h"

char *
@@ -16,8 +20,8 @@
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);
}