summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/inspircd.h3
-rw-r--r--include/inspstring.h9
-rw-r--r--src/helperfuncs.cpp13
3 files changed, 19 insertions, 6 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 9a9583499..de574b6f4 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -543,7 +543,8 @@ class CoreExport InspIRCd
* @param ...
* @return The formatted string
*/
- static const char* Format(const char* formatString, ...);
+ static const char* Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2);
+ static const char* Format(const va_list &vaList, const char* formatString) CUSTOM_PRINTF(2, 0);
static void QuickExit(int status);
diff --git a/include/inspstring.h b/include/inspstring.h
index eb7b7218f..ccc77da66 100644
--- a/include/inspstring.h
+++ b/include/inspstring.h
@@ -24,6 +24,15 @@
#include "config.h"
#include <cstring>
+/** Sets ret to the formated string. last is the last parameter before ..., and format is the format in printf-style */
+#define VAFORMAT(ret, last, format) \
+ do { \
+ va_list _vaList; \
+ va_start(_vaList, last); \
+ ret = InspIRCd::Format(_vaList, format); \
+ va_end(_vaList); \
+ } while (false);
+
/** Compose a hex string from raw data.
* @param raw The raw data to compose hex from (can be NULL if rawsize is 0)
* @param rawsize The size of the raw data buffer
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index d11a13aa0..c097b0033 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -424,19 +424,22 @@ unsigned long InspIRCd::Duration(const std::string &str)
return total + subtotal;
}
-const char* InspIRCd::Format(const char* formatString, ...)
+const char* InspIRCd::Format(const va_list &vaList, const char* formatString)
{
static std::vector<char> formatBuffer(1024);
int vsnret = 0;
-
- va_list vaList;
- va_start(vaList, formatString);
while ((vsnret = vsnprintf(&formatBuffer[0], formatBuffer.size(), formatString, vaList)) < 0 || static_cast<unsigned int>(vsnret) >= formatBuffer.size())
formatBuffer.resize(formatBuffer.size() * 2);
- va_end(vaList);
return &formatBuffer[0];
}
+const char* InspIRCd::Format(const char* formatString, ...)
+{
+ const char* ret;
+ VAFORMAT(ret, formatString, formatString);
+ return ret;
+}
+
bool InspIRCd::ULine(const std::string& sserver)
{
if (sserver.empty())