changeset 849:d7f940afd933

New portability function: strndup
author Sebastien Decugis <sdecugis@freediameter.net>
date Sun, 21 Oct 2012 17:12:13 +0200
parents 6dfa8bc2e71e
children 12e7fcbc1b21
files include/freeDiameter/CMakeLists.txt include/freeDiameter/freeDiameter-host.h.in include/freeDiameter/libfdproto.h libfdproto/portability.c
diffstat 4 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/include/freeDiameter/CMakeLists.txt	Thu Oct 18 23:00:51 2012 +0200
+++ b/include/freeDiameter/CMakeLists.txt	Sun Oct 21 17:12:13 2012 +0200
@@ -63,6 +63,9 @@
 # malloc.h ?
 CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
 
+# strndup ? Missing on OS X
+CHECK_FUNCTION_EXISTS (strndup HAVE_STRNDUP)
+
 
 ### System checks -- for includes / link
 
--- a/include/freeDiameter/freeDiameter-host.h.in	Thu Oct 18 23:00:51 2012 +0200
+++ b/include/freeDiameter/freeDiameter-host.h.in	Sun Oct 21 17:12:13 2012 +0200
@@ -42,6 +42,7 @@
 #cmakedefine HAVE_SIGNALENT_H
 #cmakedefine HAVE_AI_ADDRCONFIG
 #cmakedefine HAVE_CLOCK_GETTIME
+#cmakedefine HAVE_STRNDUP
 
 #cmakedefine HOST_BIG_ENDIAN @HOST_BIG_ENDIAN@
 
--- a/include/freeDiameter/libfdproto.h	Thu Oct 18 23:00:51 2012 +0200
+++ b/include/freeDiameter/libfdproto.h	Sun Oct 21 17:12:13 2012 +0200
@@ -611,6 +611,9 @@
   int clock_gettime(int clk_id, struct timespec* ts);
 #endif /* HAVE_CLOCK_GETTIME */
 
+#ifndef HAVE_STRNDUP
+char * strndup (char const *s, size_t n);
+#endif /* HAVE_STRNDUP */
 
 
 /*============================================================*/
--- a/libfdproto/portability.c	Thu Oct 18 23:00:51 2012 +0200
+++ b/libfdproto/portability.c	Sun Oct 21 17:12:13 2012 +0200
@@ -45,3 +45,17 @@
 	ts->tv_nsec = tv.tv_usec * 1000;
 }
 #endif /* HAVE_CLOCK_GETTIME */
+
+/* Replacement for strndup for the Mac OS */
+#ifndef HAVE_STRNDUP
+char * strndup (char *str, size_t len)
+{
+	char * output;
+	size_t outlen = strnlen (str, len);
+	CHECK_MALLOC_DO( output = malloc (outlen + 1), return NULL );
+
+	output[outlen] = '\0';
+	memcpy (output, str, outlen);
+	return output;
+}
+#endif /* HAVE_STRNDUP */
"Welcome to our mercurial repository"