Skip to content

Commit

Permalink
Windows doesn't provide strtok_r, it uses strtok_s
Browse files Browse the repository at this point in the history
so wrap it to make sure we can find it.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz authored and pcercuei committed Feb 17, 2022
1 parent 77a3f61 commit 84ad761
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions iio-config.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 84ad761

Please sign in to comment.