mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 05:15:41 +00:00
[GCC-COMPAT] Add support library for GCC's libsupc++ and libstdc++
__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++.
This commit is contained in:
parent
486a20dbc4
commit
fcbccaa194
6 changed files with 97 additions and 2 deletions
42
sdk/lib/gcc-compat/__throw_out_of_range_fmt.cpp
Normal file
42
sdk/lib/gcc-compat/__throw_out_of_range_fmt.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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
|
Loading…
Add table
Add a link
Reference in a new issue