alexcpt.cpp 599 B

123456789101112131415161718192021222324252627282930
  1. #include "config.h"
  2. #include "alexcpt.h"
  3. #include <cstdio>
  4. #include <cstdarg>
  5. #include "opthelpers.h"
  6. namespace al {
  7. backend_exception::backend_exception(ALCenum code, const char *msg, ...) : mErrorCode{code}
  8. {
  9. va_list args, args2;
  10. va_start(args, msg);
  11. va_copy(args2, args);
  12. int msglen{std::vsnprintf(nullptr, 0, msg, args)};
  13. if LIKELY(msglen > 0)
  14. {
  15. mMessage.resize(static_cast<size_t>(msglen)+1);
  16. std::vsnprintf(&mMessage[0], mMessage.length(), msg, args2);
  17. mMessage.pop_back();
  18. }
  19. va_end(args2);
  20. va_end(args);
  21. }
  22. } // namespace al