From 84ad761e7d44b1f1cbde58a9fc1d834849b074ad Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Mon, 22 Nov 2021 18:25:49 -0500 Subject: [PATCH] Windows doesn't provide strtok_r, it uses strtok_s so wrap it to make sure we can find it. Signed-off-by: Robin Getz --- CMakeLists.txt | 1 + iio-config.h.cmakein | 1 + iio-private.h | 1 + utilities.c | 11 +++++++++++ 4 files changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30576c045..698676f6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,7 @@ include(CheckSymbolExists) check_symbol_exists(strdup "string.h" HAS_STRDUP) check_symbol_exists(strndup "string.h" HAS_STRNDUP) check_symbol_exists(strerror_r "string.h" HAS_STRERROR_R) +check_symbol_exists(strtok_r "string.h" HAS_STRTOK_R) check_symbol_exists(newlocale "locale.h" HAS_NEWLOCALE) option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON) diff --git a/iio-config.h.cmakein b/iio-config.h.cmakein index ab2687dc2..6f8932536 100644 --- a/iio-config.h.cmakein +++ b/iio-config.h.cmakein @@ -28,6 +28,7 @@ #cmakedefine HAS_PIPE2 #cmakedefine HAS_STRDUP #cmakedefine HAS_STRNDUP +#cmakedefine HAS_STRTOK_R #cmakedefine HAS_STRERROR_R #cmakedefine HAS_NEWLOCALE #cmakedefine HAS_PTHREAD_SETNAME_NP diff --git a/iio-private.h b/iio-private.h index 6938a9e9c..71a46afef 100644 --- a/iio-private.h +++ b/iio-private.h @@ -261,6 +261,7 @@ unsigned int find_channel_modifier(const char *s, size_t *len_p); char *iio_strdup(const char *str); char *iio_strndup(const char *str, size_t n); +char *iio_strtok_r(char *str, const char *delim, char **saveptr); size_t iio_strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize); char * iio_getenv (char * envvar); diff --git a/utilities.c b/utilities.c index 132c75845..87b7f516e 100644 --- a/utilities.c +++ b/utilities.c @@ -213,6 +213,17 @@ void iio_strerror(int err, char *buf, size_t len) } } +char *iio_strtok_r(char *str, const char *delim, char **saveptr) +{ +#if defined(_WIN32) + return strtok_s(str, delim, saveptr); +#elif defined(HAS_STRTOK_R) + return strtok_r(str, delim, saveptr); +#else +#error Need a implentation of strtok_r for this platform +#endif +} + char *iio_strdup(const char *str) { #if defined(_WIN32)