From 73b93d707ca84f9e03efa06fa7eda075ee11188c Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 11 Nov 2015 08:54:50 +0200 Subject: [PATCH] Implemented a minimal version of ToStringF with a static buffer. --- source/Base/Shared.cpp | 21 +++++++++++++++++++++ source/Base/Shared.hpp | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/source/Base/Shared.cpp b/source/Base/Shared.cpp index d7d86796..3114ce1e 100644 --- a/source/Base/Shared.cpp +++ b/source/Base/Shared.cpp @@ -332,6 +332,27 @@ void DbgFtl(const char * type, const char * func, const char * fmt, ...) va_end(args); } +// ------------------------------------------------------------------------------------------------ +const SQChar * ToStrF(const char * fmt, ...) +{ + static char buf[128]; + // Variable arguments structure + va_list args; + // Get the specified arguments + va_start (args, fmt); + // Run the specified format + int ret = std::vsnprintf(buf, sizeof(buf), fmt, args); + // Check for formatting errors + if (ret < 0) + { + LogErr("Failed to run the specified string format"); + // Return an empty string + buf[0] = 0; + } + // Return the buffer + return buf; +} + // ------------------------------------------------------------------------------------------------ const SQChar * ToStringF(const char * fmt, ...) { diff --git a/source/Base/Shared.hpp b/source/Base/Shared.hpp index e03fa0cd..5f2dec79 100644 --- a/source/Base/Shared.hpp +++ b/source/Base/Shared.hpp @@ -109,6 +109,11 @@ void DbgWrn(const char * type, const char * func, const char * fmt, ...); void DbgErr(const char * type, const char * func, const char * fmt, ...); void DbgFtl(const char * type, const char * func, const char * fmt, ...); +/* ------------------------------------------------------------------------------------------------ + * ... +*/ +const SQChar * ToStrF(const char * fmt, ...); + /* ------------------------------------------------------------------------------------------------ * ... */