[prev in list] [next in list] [prev in thread] [next in thread] 

List:       varnish-commit
Subject:    r891 - trunk/varnish-cache/lib/libcompat
From:       des () projects ! linpro ! no (des at projects ! linpro ! no)
Date:       2006-08-22 9:31:34
Message-ID: 20060822093134.B38941EC986 () projects ! linpro ! no
[Download RAW message or body]

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);
 }
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic