From f26a9589ffbfd9530a0b1fbff2da71aa47b72d20 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 23 May 2019 22:03:38 -0600 Subject: [PATCH] Added support for printf override using XPRINTF for wolfCrypt test/benchmark. Added ability to override snprintf with XSNPRINTF. If `STRING_USER` is defined no standard lib `` or `` will be included. --- wolfcrypt/benchmark/benchmark.c | 12 ++++++++++-- wolfcrypt/test/test.c | 9 ++++++++- wolfssl/wolfcrypt/memory.h | 2 ++ wolfssl/wolfcrypt/types.h | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 853f5d010..be3576927 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -113,8 +113,16 @@ #include /* we're using malloc / free direct here */ #endif - #include - #include + #ifndef STRING_USER + #include + #include + #endif + + /* enable way for customer to override test/bench printf */ + #ifdef XPRINTF + #undef printf + #define printf XPRINTF + #endif #endif #include diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 7562b9a97..dad6753da 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -105,8 +105,15 @@ #ifdef XMALLOC_USER #include /* we're using malloc / free direct here */ #endif + #ifndef STRING_USER + #include + #endif - #include + /* enable way for customer to override test/bench printf */ + #ifdef XPRINTF + #undef printf + #define printf XPRINTF + #endif #endif #include diff --git a/wolfssl/wolfcrypt/memory.h b/wolfssl/wolfcrypt/memory.h index f9295b392..a2ed27b91 100644 --- a/wolfssl/wolfcrypt/memory.h +++ b/wolfssl/wolfcrypt/memory.h @@ -29,7 +29,9 @@ #ifndef WOLFSSL_MEMORY_H #define WOLFSSL_MEMORY_H +#ifndef STRING_USER #include +#endif #include #ifdef __cplusplus diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 6ca0b3a2d..47cc1d615 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -430,6 +430,7 @@ /* snprintf is used in asn.c for GetTimeString, PKCS7 test, and when debugging is turned on */ #ifndef USE_WINDOWS_API + #ifndef XSNPRINTF #if defined(NO_FILESYSTEM) && (defined(OPENSSL_EXTRA) || \ defined(HAVE_PKCS7)) && !defined(NO_STDIO_FILESYSTEM) /* case where stdio is not included else where but is needed @@ -437,6 +438,7 @@ #include #endif #define XSNPRINTF snprintf + #endif #else #ifdef _MSC_VER #if (_MSC_VER >= 1900)