From 6153822a2de1867b7b90b95e8ed9bc1a8c792c84 Mon Sep 17 00:00:00 2001 From: Daniel Vassdal Date: Sun, 12 May 2013 10:54:07 -0700 Subject: Added a function to replace all the ugly sprintf-ing everywhere --- include/inspircd.h | 8 ++++++++ src/helperfuncs.cpp | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/inspircd.h b/include/inspircd.h index c37658515..04327992c 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -541,6 +541,14 @@ class CoreExport InspIRCd /** Causes the server to exit immediately with exit code 0. * The status code is required for signal handlers, and ignored. */ + + /** Printf-wrapper. + * @param How you want it formatted + * @param ... + * @return The formatted string + */ + static const char* Format(const char* formatString, ...); + static void QuickExit(int status); /** Return a count of channels on the network diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index c7287e661..8a74a64e4 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -424,6 +424,19 @@ unsigned long InspIRCd::Duration(const std::string &str) return total + subtotal; } +const char* InspIRCd::Format(const char* formatString, ...) +{ + static std::vector formatBuffer(1024); + int vsnret = 0; + + va_list vaList; + va_start(vaList, formatString); + while ((vsnret = vsnprintf(&formatBuffer[0], formatBuffer.size(), formatString, vaList)) < 0 || static_cast(vsnret) >= formatBuffer.size()) + formatBuffer.resize(formatBuffer.size() * 2); + va_end(vaList); + return &formatBuffer[0]; +} + bool InspIRCd::ULine(const std::string& sserver) { if (sserver.empty()) -- cgit v1.2.3