diff --git a/cmake/PerformFeatureChecks.cmake b/cmake/PerformFeatureChecks.cmake index 885892fa90..8e5e7a245a 100644 --- a/cmake/PerformFeatureChecks.cmake +++ b/cmake/PerformFeatureChecks.cmake @@ -77,6 +77,7 @@ macro( perform_feature_checks ) check_symbol_exists( strncasecmp "string.h" HAVE_STRNCASECMP ) check_symbol_exists( strncasecmp "strings.h" HAVE_STRNCASECMP ) check_symbol_exists( strtok_r "string.h" HAVE_STRTOKR ) + check_symbol_exists( strtok_s "string.h" HAVE_STRTOKS ) check_cxx_symbol_exists( strcasecmp "string.h" HAVE_STRCASECMP ) check_cxx_symbol_exists( strncasecmp "string.h" HAVE_STRNCASECMP ) diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 3a41b34f24..8bcd3a1ca8 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -7,7 +7,15 @@ #cmakedefine HAVE_STRNCASECMP +#cmakedefine HAVE_STRTOKS +#ifdef HAVE_STRTOKS +// strtok_s is the actual C11 standard rather than posix strtok_r +// but its also an optional standard, MSVC supports it, so alias it +#define HAVE_STRTOKR +#define strtok_r strtok_s +#else #cmakedefine HAVE_STRTOKR // spelled oddly to differ from wx's similar test +#endif // Handle platform differences in math.h #cmakedefine HAVE_MATH_H diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index d9211a18bc..b5d94db468 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -412,10 +412,6 @@ if( TRUE OR NOT USE_KIWAY_DLLS ) endif() endif() -if( NOT HAVE_STRTOKR ) - list( APPEND COMMON_SRCS strtok_r.c ) -endif() - list( APPEND COMMON_SRCS kicad_curl/kicad_curl.cpp kicad_curl/kicad_curl_easy.cpp diff --git a/common/strtok_r.c b/common/strtok_r.c deleted file mode 100644 index a0b099706a..0000000000 --- a/common/strtok_r.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * public domain strtok_r() - */ - -#include - -char* strtok_r( char* str, const char* delim, char** nextp ) -{ - char* ret; - - if( str == NULL ) - { - str = *nextp; - } - - str += strspn( str, delim ); - - if( *str == '\0' ) - { - return NULL; - } - - ret = str; - - str += strcspn( str, delim ); - - if( *str ) - { - *str++ = '\0'; - } - - *nextp = str; - - return ret; -} diff --git a/include/string_utils.h b/include/string_utils.h index 3c26431581..f48c8303ba 100644 --- a/include/string_utils.h +++ b/include/string_utils.h @@ -24,8 +24,6 @@ #ifndef STRING_UTILS_H #define STRING_UTILS_H -#include "config.h" - #include #include #include @@ -230,11 +228,6 @@ wxString GetIllegalFileNameWxChars(); bool ReplaceIllegalFileNameChars( std::string* aName, int aReplaceChar = 0 ); bool ReplaceIllegalFileNameChars( wxString& aName, int aReplaceChar = 0 ); -#ifndef HAVE_STRTOKR -// common/strtok_r.c optionally: -extern "C" char* strtok_r( char* str, const char* delim, char** nextp ); -#endif - /** * A helper for sorting strings from the rear.