forked from wolfSSL/wolfssl
Fixes to resolve issues with c99 compliance (building with ./configure CFLAGS="-std=c99"
).
* Fix for ReadDir checking for file flag to use `S_ISREG(ctx->s.st_mode)` syntax. * Added macro for strsep `XSTRSEP`. Added wolf implementation as `wc_strsep` enabled as C99 or `USE_WOLF_STRSEP`. * Fix to use `gethostbyname` for c99 instead of `getaddrinfo`. * For c99 use wolf strtok `wc_strtok`. * Exposed API's for `wc_strtok` and `wc_strsep` when available. * Include `sys/time.h` when available from autocon `HAVE_SYS_TIME_H` or c99. * include `<strings.h>` when `HAVE_STRINGS_H` or c99.
This commit is contained in:
@@ -449,7 +449,7 @@ static void test_harness(void* vargs)
|
|||||||
break;
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
/* Ignore lines that start with a #. */
|
/* Ignore lines that start with a #. */
|
||||||
comment = strsep(&cursor, "\n");
|
comment = XSTRSEP(&cursor, "\n");
|
||||||
#ifdef DEBUG_SUITE_TESTS
|
#ifdef DEBUG_SUITE_TESTS
|
||||||
printf("%s\n", comment);
|
printf("%s\n", comment);
|
||||||
#else
|
#else
|
||||||
@@ -460,18 +460,18 @@ static void test_harness(void* vargs)
|
|||||||
/* Parameters start with a -. They end in either a newline
|
/* Parameters start with a -. They end in either a newline
|
||||||
* or a space. Capture until either, save in Args list. */
|
* or a space. Capture until either, save in Args list. */
|
||||||
if (cliMode)
|
if (cliMode)
|
||||||
cliArgs[cliArgsSz++] = strsep(&cursor, " \n");
|
cliArgs[cliArgsSz++] = XSTRSEP(&cursor, " \n");
|
||||||
else
|
else
|
||||||
svrArgs[svrArgsSz++] = strsep(&cursor, " \n");
|
svrArgs[svrArgsSz++] = XSTRSEP(&cursor, " \n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Anything from cursor until end of line that isn't the above
|
/* Anything from cursor until end of line that isn't the above
|
||||||
* is data for a paramter. Just up until the next newline in
|
* is data for a paramter. Just up until the next newline in
|
||||||
* the Args list. */
|
* the Args list. */
|
||||||
if (cliMode)
|
if (cliMode)
|
||||||
cliArgs[cliArgsSz++] = strsep(&cursor, "\n");
|
cliArgs[cliArgsSz++] = XSTRSEP(&cursor, "\n");
|
||||||
else
|
else
|
||||||
svrArgs[svrArgsSz++] = strsep(&cursor, "\n");
|
svrArgs[svrArgsSz++] = XSTRSEP(&cursor, "\n");
|
||||||
if (*cursor == 0) /* eof */
|
if (*cursor == 0) /* eof */
|
||||||
do_it = 1;
|
do_it = 1;
|
||||||
}
|
}
|
||||||
|
@@ -265,7 +265,7 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name)
|
|||||||
WOLFSSL_MSG("stat on name failed");
|
WOLFSSL_MSG("stat on name failed");
|
||||||
ret = BAD_PATH_ERROR;
|
ret = BAD_PATH_ERROR;
|
||||||
break;
|
break;
|
||||||
} else if (ctx->s.st_mode & S_IFREG) {
|
} else if (S_ISREG(ctx->s.st_mode)) {
|
||||||
if (name)
|
if (name)
|
||||||
*name = ctx->name;
|
*name = ctx->name;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -312,7 +312,7 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name)
|
|||||||
WOLFSSL_MSG("stat on name failed");
|
WOLFSSL_MSG("stat on name failed");
|
||||||
ret = BAD_PATH_ERROR;
|
ret = BAD_PATH_ERROR;
|
||||||
break;
|
break;
|
||||||
} else if (ctx->s.st_mode & S_IFREG) {
|
} else if (S_ISREG(ctx->s.st_mode)) {
|
||||||
if (name)
|
if (name)
|
||||||
*name = ctx->name;
|
*name = ctx->name;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -419,6 +419,33 @@ char* wc_strtok(char *str, const char *delim, char **nextp)
|
|||||||
}
|
}
|
||||||
#endif /* USE_WOLF_STRTOK */
|
#endif /* USE_WOLF_STRTOK */
|
||||||
|
|
||||||
|
#ifdef USE_WOLF_STRSEP
|
||||||
|
char* wc_strsep(char **stringp, const char *delim)
|
||||||
|
{
|
||||||
|
char *s, *tok;
|
||||||
|
const char *spanp;
|
||||||
|
|
||||||
|
/* null check */
|
||||||
|
if (stringp == NULL || *stringp == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
s = *stringp;
|
||||||
|
for (tok = s; *tok; ++tok) {
|
||||||
|
for (spanp = delim; *spanp; ++spanp) {
|
||||||
|
/* found delimiter */
|
||||||
|
if (*tok == *spanp) {
|
||||||
|
*tok = '\0'; /* replace delim with null term */
|
||||||
|
*stringp = tok + 1; /* return past delim */
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*stringp = NULL;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
#endif /* USE_WOLF_STRSEP */
|
||||||
|
|
||||||
#if WOLFSSL_CRYPT_HW_MUTEX
|
#if WOLFSSL_CRYPT_HW_MUTEX
|
||||||
/* Mutex for protection of cryptography hardware */
|
/* Mutex for protection of cryptography hardware */
|
||||||
static wolfSSL_Mutex wcCryptHwMutex;
|
static wolfSSL_Mutex wcCryptHwMutex;
|
||||||
|
@@ -297,9 +297,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(USE_WOLF_STRTOK) && \
|
#if !defined(USE_WOLF_STRTOK) && \
|
||||||
(defined(__MINGW32__) || defined(WOLFSSL_TIRTOS))
|
(defined(__MINGW32__) || defined(WOLFSSL_TIRTOS) || defined(WOLF_C99))
|
||||||
#define USE_WOLF_STRTOK
|
#define USE_WOLF_STRTOK
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(USE_WOLF_STRSEP) && (defined(WOLF_C99))
|
||||||
|
#define USE_WOLF_STRSEP
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef STRING_USER
|
#ifndef STRING_USER
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -317,12 +320,21 @@
|
|||||||
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
|
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
|
||||||
#define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
|
#define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
|
||||||
|
|
||||||
|
#ifdef USE_WOLF_STRSEP
|
||||||
|
#define XSTRSEP(s1,d) wc_strsep((s1),(d))
|
||||||
|
#else
|
||||||
|
#define XSTRSEP(s1,d) strsep((s1),(d))
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS)
|
#if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS)
|
||||||
/* XC32 does not support strncasecmp, so use case sensitive one */
|
/* XC32 does not support strncasecmp, so use case sensitive one */
|
||||||
#define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n))
|
#define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n))
|
||||||
#elif defined(USE_WINDOWS_API)
|
#elif defined(USE_WINDOWS_API)
|
||||||
#define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
|
#define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
|
||||||
#else
|
#else
|
||||||
|
#if defined(HAVE_STRINGS_H) || defined(WOLF_C99)
|
||||||
|
#include <strings.h>
|
||||||
|
#endif
|
||||||
#define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
|
#define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -343,17 +355,20 @@
|
|||||||
#if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
|
#if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
|
||||||
/* use only Thread Safe version of strtok */
|
/* use only Thread Safe version of strtok */
|
||||||
#if defined(USE_WOLF_STRTOK)
|
#if defined(USE_WOLF_STRTOK)
|
||||||
#define XSTRTOK wc_strtok
|
#define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
|
||||||
#elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
|
#elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
|
||||||
#define XSTRTOK strtok_s
|
#define XSTRTOK(s1,d,ptr) strtok_s((s1),(d),(ptr))
|
||||||
#else
|
#else
|
||||||
#define XSTRTOK strtok_r
|
#define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_WOLF_STRTOK
|
#ifdef USE_WOLF_STRTOK
|
||||||
WOLFSSL_LOCAL char* wc_strtok(char *str, const char *delim, char **nextp);
|
WOLFSSL_API char* wc_strtok(char *str, const char *delim, char **nextp);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_WOLF_STRSEP
|
||||||
|
WOLFSSL_API char* wc_strsep(char **stringp, const char *delim);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
|
#if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
|
||||||
|
@@ -33,6 +33,12 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* detect C99 */
|
||||||
|
#if defined(__STDC_VERSION__)
|
||||||
|
#if __STDC_VERSION__ >= 199901L
|
||||||
|
#define WOLF_C99
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_API
|
#ifdef USE_WINDOWS_API
|
||||||
#ifdef WOLFSSL_GAME_BUILD
|
#ifdef WOLFSSL_GAME_BUILD
|
||||||
@@ -407,6 +413,9 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
|||||||
/* default */
|
/* default */
|
||||||
/* uses complete <time.h> facility */
|
/* uses complete <time.h> facility */
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#if defined(HAVE_SYS_TIME_H) || defined(WOLF_C99)
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* PowerPC time_t is int */
|
/* PowerPC time_t is int */
|
||||||
#ifdef __PPC__
|
#ifdef __PPC__
|
||||||
@@ -420,7 +429,7 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
|||||||
#define XTIME(tl) time((tl))
|
#define XTIME(tl) time((tl))
|
||||||
#endif
|
#endif
|
||||||
#if !defined(XGMTIME) && !defined(TIME_OVERRIDES)
|
#if !defined(XGMTIME) && !defined(TIME_OVERRIDES)
|
||||||
#if defined(WOLFSSL_GMTIME) || !defined(HAVE_GMTIME_R)
|
#if defined(WOLFSSL_GMTIME) || !defined(HAVE_GMTIME_R) || defined(WOLF_C99)
|
||||||
#define XGMTIME(c, t) gmtime((c))
|
#define XGMTIME(c, t) gmtime((c))
|
||||||
#else
|
#else
|
||||||
#define XGMTIME(c, t) gmtime_r((c), (t))
|
#define XGMTIME(c, t) gmtime_r((c), (t))
|
||||||
|
@@ -262,6 +262,11 @@
|
|||||||
typedef struct hostent HOSTENT;
|
typedef struct hostent HOSTENT;
|
||||||
#endif /* HAVE_SOCKADDR */
|
#endif /* HAVE_SOCKADDR */
|
||||||
|
|
||||||
|
/* use gethostbyname for c99 */
|
||||||
|
#ifdef WOLF_C99
|
||||||
|
#undef HAVE_GETADDRINFO
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GETADDRINFO
|
#ifdef HAVE_GETADDRINFO
|
||||||
typedef struct addrinfo ADDRINFO;
|
typedef struct addrinfo ADDRINFO;
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user