0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd: Drop in ircd::fmt for stdarg for ircd::exception.

This commit is contained in:
Jason Volk 2017-03-17 17:37:40 -07:00
parent 86804755c8
commit e64ca2827d
2 changed files with 16 additions and 22 deletions

View file

@ -55,8 +55,8 @@ struct exception
char buf[BUFSIZE];
ssize_t generate(const char *const &name, const char *const &fmt, va_list ap) noexcept;
ssize_t generate(const char *const &fmt, va_list ap) noexcept;
ssize_t generate(const char *const &name, const char *const &fmt, const va_rtti &ap) noexcept;
ssize_t generate(const char *const &fmt, const va_rtti &ap) noexcept;
public:
const char *what() const noexcept override
@ -106,13 +106,11 @@ struct exception
struct name \
:parent \
{ \
name(const char *const fmt = " ", ...) noexcept AFP(2, 3) \
template<class... args> \
name(const char *const fmt = " ", args&&... ap) noexcept \
:parent{generate_skip} \
{ \
va_list ap; \
va_start(ap, fmt); \
generate(#name, fmt, ap); \
va_end(ap); \
generate(#name, fmt, va_rtti{std::forward<args>(ap)...}); \
} \
\
name(const generate_skip_t) noexcept \
@ -125,13 +123,11 @@ struct name \
struct name \
:parent \
{ \
name(const char *const fmt, ...) noexcept AFP(2, 3) \
parent{generate_skip_t} \
template<class... args> \
name(const char *const fmt = " ", args&&... ap) noexcept \
:parent{generate_skip_t} \
{ \
va_list ap; \
va_start(ap, fmt); \
generate(fmt, ap); \
va_end(ap); \
generate(fmt, va_rtti{std::forward<args>(ap)...}); \
} \
\
name(const generate_skip_t = {}) noexcept \

View file

@ -23,20 +23,18 @@
*
*/
using namespace ircd;
ssize_t
exception::generate(const char *const &fmt,
va_list ap)
ircd::exception::generate(const char *const &fmt,
const va_rtti &ap)
noexcept
{
return vsnprintf(buf, sizeof(buf), fmt, ap);
return fmt::vsnprintf(buf, sizeof(buf), fmt, ap);
}
ssize_t
exception::generate(const char *const &name,
const char *const &fmt,
va_list ap)
ircd::exception::generate(const char *const &name,
const char *const &fmt,
const va_rtti &ap)
noexcept
{
size_t size(0);
@ -44,7 +42,7 @@ noexcept
size = strlcat(buf, name, sizeof(buf));
size = strlcat(buf, empty? "." : ": ", sizeof(buf));
if(size < sizeof(buf))
size += vsnprintf(buf + size, sizeof(buf) - size, fmt, ap);
size += fmt::vsnprintf(buf + size, sizeof(buf) - size, fmt, ap);
return size;
}