diff options
author | DukePyrolator <DukePyrolator@anope.org> | 2011-02-13 20:06:01 +0100 |
---|---|---|
committer | DukePyrolator <DukePyrolator@anope.org> | 2011-02-13 20:06:01 +0100 |
commit | d436e4ca4a0043272061c64468b630168267dabe (patch) | |
tree | 747efbd8978348b0359b95b18b2a2398b33f9a52 | |
parent | 1372dc19537ce270f1f02979101f9b8678b5ff28 (diff) |
added Anope::printf()
-rw-r--r-- | include/anope.h | 9 | ||||
-rw-r--r-- | src/misc.cpp | 18 |
2 files changed, 27 insertions, 0 deletions
diff --git a/include/anope.h b/include/anope.h index 56d893278..ec1d083a5 100644 --- a/include/anope.h +++ b/include/anope.h @@ -329,6 +329,15 @@ namespace Anope extern CoreExport void Unhex(const Anope::string &src, Anope::string &dest); extern CoreExport void Unhex(const Anope::string &src, char *dest); + /** Returns a sequence of data formatted as the format argument specifies. + ** After the format parameter, the function expects at least as many + ** additional arguments as specified in format. + * @param fmt Format of the Message + * @param ... any number of parameters + * @return a Anope::string + */ + extern CoreExport string printf(const char *fmt, ...); + /** Return the last error, uses errno/GetLastError() to determin this * @return An error message */ diff --git a/src/misc.cpp b/src/misc.cpp index daf7fe363..fe216fff8 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -832,6 +832,24 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case return m == mask_len; } +/** Returns a sequence of data formatted as the format argument specifies. + ** After the format parameter, the function expects at least as many + ** additional arguments as specified in format. + * @param fmt Format of the Message + * @param ... any number of parameters + * @return a Anope::string + */ +Anope::string Anope::printf(const char *fmt, ...) +{ + va_list args; + char buf[1024]; + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + return buf; +} + + /* * strlcat and strlcpy were ripped from openssh 2.5.1p2 * They had the following Copyright info: |