]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
windows: Provide a strndup(3) replacement
authorMartin Willi <martin@revosec.ch>
Fri, 25 Oct 2013 14:41:48 +0000 (16:41 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:53:02 +0000 (15:53 +0200)
src/libstrongswan/utils/windows.c
src/libstrongswan/utils/windows.h

index feefcd49750f758cc11defed8795fbc17cb5352d..48a70b6c29ae7354f5beb8d32b699d0cf8a992f1 100644 (file)
@@ -49,6 +49,21 @@ int usleep(useconds_t usec)
        return 0;
 }
 
+/**
+ * See header.
+ */
+char* strndup(const char *s, size_t n)
+{
+       char *dst;
+
+       n = min(strnlen(s, n), n);
+       dst = malloc(n + 1);
+       memcpy(dst, s, n);
+       dst[n] = '\0';
+
+       return dst;
+}
+
 /*
  * See header.
  */
index e070a79a2f545d405a20e928d617550ac5670276..4e1e6b6c26d8b0daf1a199ad6f3c3dabb4499408 100644 (file)
@@ -105,6 +105,11 @@ static inline char* strdup_windows(const char *src)
        return dst;
 }
 
+/**
+ * strndup(3)
+ */
+char* strndup(const char *s, size_t n);
+
 /**
  * Provided via ws2_32
  */