From: Martin Willi Date: Fri, 25 Oct 2013 14:41:48 +0000 (+0200) Subject: windows: Provide a strndup(3) replacement X-Git-Tag: 5.2.0dr6~24^2~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3c809e615f0e8eb476efcc85a3c8cf2cbe3f7c3;p=thirdparty%2Fstrongswan.git windows: Provide a strndup(3) replacement --- diff --git a/src/libstrongswan/utils/windows.c b/src/libstrongswan/utils/windows.c index feefcd4975..48a70b6c29 100644 --- a/src/libstrongswan/utils/windows.c +++ b/src/libstrongswan/utils/windows.c @@ -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. */ diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h index e070a79a2f..4e1e6b6c26 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -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 */