diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 335675cf1..6d28158f8 100755 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -348,6 +348,59 @@ wolfSSL_Mutex* wc_InitAndAllocMutex(void) return m; } +#ifdef USE_WOLF_STRTOK +/* String token (delim) search. If str is null use nextp. */ +char* wc_strtok(char *str, const char *delim, char **nextp) +{ + char* ret; + int i, j; + + /* Use next if str is NULL */ + if (str == NULL && nextp) + str = *nextp; + + /* verify str input */ + if (str == NULL || *str == '\0') + return NULL; + + /* match on entire delim */ + for (i = 0; str[i]; i++) { + for (j = 0; delim[j]; j++) { + if (delim[j] == str[i]) + break; + } + if (!delim[j]) + break; + } + str += i; + /* if end of string, not found so return NULL */ + if (*str == '\0') + return NULL; + + ret = str; + + /* match on first delim */ + for (i = 0; str[i]; i++) { + for (j = 0; delim[j]; j++) { + if (delim[j] == str[i]) + break; + } + if (delim[j] == str[i]) + break; + } + str += i; + + /* null terminate found string */ + if (*str) + *str++ = '\0'; + + /* return pointer to next */ + if (nextp) + *nextp = str; + + return ret; +} +#endif /* USE_WOLF_STRTOK */ #if WOLFSSL_CRYPT_HW_MUTEX /* Mutex for protection of cryptography hardware */ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 917e0f2b1..942787191 100755 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -326,15 +326,11 @@ /* use only Thread Safe version of strtok */ #if !defined(USE_WINDOWS_API) && !defined(INTIME_RTOS) #define XSTRTOK strtok_r + #elif defined(__MINGW32__) + #define USE_WOLF_STRTOK + #define XSTRTOK wc_strtok #else #define XSTRTOK strtok_s - - #ifdef __MINGW32__ - #pragma GCC diagnostic push - #pragma GCC diagnostic warning "-Wcpp" - #warning "MinGW may be missing strtok_s. You can find a public domain implementation here: https://github.com/fletcher/MultiMarkdown-4/blob/master/strtok.c" - #pragma GCC diagnostic pop - #endif #endif #endif #endif diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 2247d5360..5a4d56a23 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -308,6 +308,9 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #endif /* !NO_FILESYSTEM */ +#ifdef USE_WOLF_STRTOK + WOLFSSL_LOCAL char* wc_strtok(char *str, const char *delim, char **nextp); +#endif /* Windows API defines its own min() macro. */ #if defined(USE_WINDOWS_API)