From ed334c414dfe784513bc3c495386d103b12f97c3 Mon Sep 17 00:00:00 2001 From: Koutaro Mukai Date: Thu, 30 Mar 2023 01:09:14 +0900 Subject: [PATCH] Implementation of vasprintf emulation (#243) * Consolidate vasprintf for non _GNU_SOURCE * va_copy on Visual Studio 2010 * Use vsnprintf_s instead * Integrate macros into function * Update platformio-ci image --- .circleci/config.yml | 2 +- include/plog/Util.h | 27 +++++++++++++++++---------- samples/Arduino/platformio.ini | 5 +++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 708a765..9eb2284 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: - run: cmake -H. -Bbuild -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE && cd build && make -j platformio: docker: - - image: sergiusthebest/platformio-ci:latest + - image: ghcr.io/sergiusthebest/platformio-ci:latest steps: - checkout - run: pio run -d samples/Arduino diff --git a/include/plog/Util.h b/include/plog/Util.h index efce8fc..6a11314 100644 --- a/include/plog/Util.h +++ b/include/plog/Util.h @@ -189,18 +189,25 @@ namespace plog #endif } -#ifdef _WIN32 +#ifndef _GNU_SOURCE inline int vasprintf(char** strp, const char* format, va_list ap) { -#if defined(__BORLANDC__) - int charCount = 0x1000; // there is no _vscprintf on Borland/Embarcadero + va_list ap_copy; +#if defined(_MSC_VER) && _MSC_VER <= 1600 + ap_copy = ap; // there is no va_copy on Visual Studio 2010 #else - int charCount = _vscprintf(format, ap); + va_copy(ap_copy, ap); +#endif +#ifndef __STDC_SECURE_LIB__ + int charCount = vsnprintf(NULL, 0, format, ap_copy); +#else + int charCount = vsnprintf_s(NULL, 0, static_cast(-1), format, ap_copy); +#endif + va_end(ap_copy); if (charCount < 0) { return -1; } -#endif size_t bufferCharCount = static_cast(charCount) + 1; @@ -210,12 +217,10 @@ namespace plog return -1; } -#if defined(__BORLANDC__) - int retval = vsnprintf_s(str, bufferCharCount, format, ap); -#elif defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) - int retval = _vsnprintf(str, bufferCharCount, format, ap); +#ifndef __STDC_SECURE_LIB__ + int retval = vsnprintf(str, bufferCharCount, format, ap); #else - int retval = _vsnprintf_s(str, bufferCharCount, charCount, format, ap); + int retval = vsnprintf_s(str, bufferCharCount, static_cast(-1), format, ap); #endif if (retval < 0) { @@ -226,7 +231,9 @@ namespace plog *strp = str; return retval; } +#endif +#ifdef _WIN32 inline int vaswprintf(wchar_t** strp, const wchar_t* format, va_list ap) { #if defined(__BORLANDC__) diff --git a/samples/Arduino/platformio.ini b/samples/Arduino/platformio.ini index 449d621..b3e60ba 100644 --- a/samples/Arduino/platformio.ini +++ b/samples/Arduino/platformio.ini @@ -20,3 +20,8 @@ framework = arduino platform = espressif32 board = esp32dev framework = arduino + +[env:pico] +platform = raspberrypi +board = pico +framework = arduino