mirror of
https://github.com/reactos/reactos.git
synced 2024-11-01 12:26:32 +00:00
fcbccaa194
__throw_out_of_range_fmt is implemented in libstdc++, but it is needed by libsupc++ and that would mean we would have to link all C++ code to libstdc++.
43 lines
992 B
C++
43 lines
992 B
C++
/*
|
|
* PROJECT: GCC c++ support library
|
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
|
* PURPOSE: __throw_out_of_range_fmt implementation
|
|
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
|
|
*/
|
|
|
|
#include <stdexcept>
|
|
#include <cstdarg>
|
|
#include <cstring>
|
|
#include <malloc.h>
|
|
|
|
namespace std {
|
|
|
|
class out_of_range_error : public exception
|
|
{
|
|
char* m_msg;
|
|
public:
|
|
explicit out_of_range_error(const char* msg) noexcept
|
|
{
|
|
size_t len = strlen(msg) + 1;
|
|
m_msg = (char*)malloc(len);
|
|
strcpy(m_msg, msg);
|
|
}
|
|
virtual ~out_of_range_error() { free(m_msg); };
|
|
virtual const char* what() const noexcept { return m_msg; }
|
|
};
|
|
|
|
void __throw_out_of_range_fmt(const char *format, ...)
|
|
{
|
|
char buffer[1024];
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
_vsnprintf(buffer, sizeof(buffer), format, argptr);
|
|
buffer[sizeof(buffer) - 1] = 0;
|
|
va_end(argptr);
|
|
|
|
throw out_of_range_error(buffer);
|
|
}
|
|
|
|
} // namespace std
|