forked from wolfSSL/wolfssl
Enhancement to add strtok implementation for platforms where it is not available such as MinGW.
This commit is contained in:
@ -348,6 +348,59 @@ wolfSSL_Mutex* wc_InitAndAllocMutex(void)
|
|||||||
return m;
|
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
|
#if WOLFSSL_CRYPT_HW_MUTEX
|
||||||
/* Mutex for protection of cryptography hardware */
|
/* Mutex for protection of cryptography hardware */
|
||||||
|
@ -326,15 +326,11 @@
|
|||||||
/* use only Thread Safe version of strtok */
|
/* use only Thread Safe version of strtok */
|
||||||
#if !defined(USE_WINDOWS_API) && !defined(INTIME_RTOS)
|
#if !defined(USE_WINDOWS_API) && !defined(INTIME_RTOS)
|
||||||
#define XSTRTOK strtok_r
|
#define XSTRTOK strtok_r
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
#define USE_WOLF_STRTOK
|
||||||
|
#define XSTRTOK wc_strtok
|
||||||
#else
|
#else
|
||||||
#define XSTRTOK strtok_s
|
#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
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -308,6 +308,9 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
|||||||
|
|
||||||
#endif /* !NO_FILESYSTEM */
|
#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. */
|
/* Windows API defines its own min() macro. */
|
||||||
#if defined(USE_WINDOWS_API)
|
#if defined(USE_WINDOWS_API)
|
||||||
|
Reference in New Issue
Block a user