From 9ccaba3ca8efe5e5f6cb536e242b93f3448c96be Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 12 Jan 2014 23:26:13 -0800 Subject: [PATCH] snprintf windows fixes --- interface/src/windowshacks.h | 39 +++++++++++++++++++++++++++++++-- libraries/shared/src/PerfStat.h | 1 - 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/interface/src/windowshacks.h b/interface/src/windowshacks.h index 759e1f3014..b186df4a21 100644 --- a/interface/src/windowshacks.h +++ b/interface/src/windowshacks.h @@ -28,10 +28,45 @@ inline double roundf(double value) { return (value > 0.0) ? floor(value + 0.5) : ceil(value - 0.5); } - - #define round roundf + + +#ifdef _MSC_VER +#ifndef SNPRINTF_FIX +#define SNPRINTF_FIX +#include +#include + +#define snprintf c99_snprintf + +inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) +{ + int count = -1; + + if (size != 0) + count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); + if (count == -1) + count = _vscprintf(format, ap); + + return count; +} + +inline int c99_snprintf(char* str, size_t size, const char* format, ...) +{ + int count; + va_list ap; + + va_start(ap, format); + count = c99_vsnprintf(str, size, format, ap); + va_end(ap); + + return count; +} +#endif // SNPRINTF_FIX + +#endif // _MSC_VER + #endif // WIN32 diff --git a/libraries/shared/src/PerfStat.h b/libraries/shared/src/PerfStat.h index 311ab5ed91..2e56526495 100644 --- a/libraries/shared/src/PerfStat.h +++ b/libraries/shared/src/PerfStat.h @@ -17,7 +17,6 @@ #include "SharedUtil.h" #ifdef _WIN32 -#define snprintf _snprintf #include "Systime.h" #else #include