r882 - in trunk/varnish-cache: . bin/varnishd include include/compat lib/libcompat

des at projects.linpro.no des at projects.linpro.no
Tue Aug 22 09:11:59 CEST 2006


Author: des
Date: 2006-08-22 09:11:59 +0200 (Tue, 22 Aug 2006)
New Revision: 882

Added:
   trunk/varnish-cache/include/compat/strndup.h
   trunk/varnish-cache/lib/libcompat/strndup.c
Modified:
   trunk/varnish-cache/bin/varnishd/tcp.c
   trunk/varnish-cache/configure.ac
   trunk/varnish-cache/include/Makefile.am
   trunk/varnish-cache/lib/libcompat/Makefile.am
Log:
Add strndup() to libcompat.

Modified: trunk/varnish-cache/bin/varnishd/tcp.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/tcp.c	2006-08-21 20:42:47 UTC (rev 881)
+++ trunk/varnish-cache/bin/varnishd/tcp.c	2006-08-22 07:11:59 UTC (rev 882)
@@ -17,6 +17,10 @@
 #ifndef HAVE_STRLCPY
 #include "compat/strlcpy.h"
 #endif
+#ifndef HAVE_STRNDUP
+#include "compat/strndup.h"
+#endif
+
 #include "mgt.h"
 
 /*--------------------------------------------------------------------*/
@@ -75,19 +79,6 @@
 }
 #endif
 
-static char *
-strndup(const char *p, unsigned n)
-{
-	char *q;
-
-	q = malloc(n + 1);
-	if (q != NULL) {
-		memcpy(q, p, n);
-		q[n] = '\0';
-	}
-	return (q);
-}
-
 int
 TCP_parse(const char *str, char **addr, char **port)
 {

Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac	2006-08-21 20:42:47 UTC (rev 881)
+++ trunk/varnish-cache/configure.ac	2006-08-22 07:11:59 UTC (rev 882)
@@ -71,6 +71,7 @@
 AC_CHECK_FUNCS([setproctitle])
 AC_CHECK_FUNCS([srandomdev])
 AC_CHECK_FUNCS([strlcat strlcpy])
+AC_CHECK_FUNCS([strndup])
 AC_CHECK_FUNCS([vis strvis strvisx])
 
 # On some systems, clock_gettime is in librt rather than libc

Modified: trunk/varnish-cache/include/Makefile.am
===================================================================
--- trunk/varnish-cache/include/Makefile.am	2006-08-21 20:42:47 UTC (rev 881)
+++ trunk/varnish-cache/include/Makefile.am	2006-08-22 07:11:59 UTC (rev 882)
@@ -10,6 +10,7 @@
 	compat/srandomdev.h \
 	compat/strlcat.h \
 	compat/strlcpy.h \
+	compat/strndup.h \
 	compat/vasprintf.h \
 	compat/vis.h \
 	hash.h \

Added: trunk/varnish-cache/include/compat/strndup.h
===================================================================
--- trunk/varnish-cache/include/compat/strndup.h	2006-08-21 20:42:47 UTC (rev 881)
+++ trunk/varnish-cache/include/compat/strndup.h	2006-08-22 07:11:59 UTC (rev 882)
@@ -0,0 +1,12 @@
+/*
+ * $Id$
+ */
+
+#ifndef COMPAT_STRNDUP_H_INCLUDED
+#define COMPAT_STRNDUP_H_INCLUDED
+
+#ifndef HAVE_STRNDUP
+char *strndup(const char *str, size_t len);
+#endif
+
+#endif


Property changes on: trunk/varnish-cache/include/compat/strndup.h
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/varnish-cache/lib/libcompat/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libcompat/Makefile.am	2006-08-21 20:42:47 UTC (rev 881)
+++ trunk/varnish-cache/lib/libcompat/Makefile.am	2006-08-22 07:11:59 UTC (rev 882)
@@ -11,6 +11,7 @@
 	srandomdev.c \
 	strlcat.c \
 	strlcpy.c \
+	strndup.c \
 	vis.c
 
 libcompat_a_CFLAGS = -include config.h

Added: trunk/varnish-cache/lib/libcompat/strndup.c
===================================================================
--- trunk/varnish-cache/lib/libcompat/strndup.c	2006-08-21 20:42:47 UTC (rev 881)
+++ trunk/varnish-cache/lib/libcompat/strndup.c	2006-08-22 07:11:59 UTC (rev 882)
@@ -0,0 +1,24 @@
+/*
+ * $Id$
+ *
+ */
+
+#ifndef HAVE_STRNDUP
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "compat/strndup.h"
+
+char *
+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);
+	return (dup);
+}
+
+#endif


Property changes on: trunk/varnish-cache/lib/libcompat/strndup.c
___________________________________________________________________
Name: svn:keywords
   + Id




More information about the varnish-commit mailing list