mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4eb5f3c9d | ||
|
|
cc2e453b5b |
@@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
project(toml11 VERSION 3.8.0)
|
project(toml11 VERSION 3.8.1)
|
||||||
|
|
||||||
option(toml11_BUILD_TEST "Build toml tests" OFF)
|
option(toml11_BUILD_TEST "Build toml tests" OFF)
|
||||||
option(toml11_INSTALL "Install CMake targets during install step." ON)
|
option(toml11_INSTALL "Install CMake targets during install step." ON)
|
||||||
|
|||||||
2
toml.hpp
2
toml.hpp
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#define TOML11_VERSION_MAJOR 3
|
#define TOML11_VERSION_MAJOR 3
|
||||||
#define TOML11_VERSION_MINOR 8
|
#define TOML11_VERSION_MINOR 8
|
||||||
#define TOML11_VERSION_PATCH 0
|
#define TOML11_VERSION_PATCH 1
|
||||||
|
|
||||||
#include "toml/parser.hpp"
|
#include "toml/parser.hpp"
|
||||||
#include "toml/literal.hpp"
|
#include "toml/literal.hpp"
|
||||||
|
|||||||
@@ -14,62 +14,14 @@
|
|||||||
namespace toml
|
namespace toml
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
|
|
||||||
inline std::string str_error(int errnum)
|
|
||||||
{
|
|
||||||
// C++ standard strerror is not thread-safe.
|
|
||||||
// C11 provides thread-safe version of this function, `strerror_s`, but it
|
|
||||||
// is not available in C++.
|
|
||||||
// To avoid using std::strerror, we need to use platform-specific functions.
|
|
||||||
// If none of the conditions are met, it calls std::strerror as a fallback.
|
|
||||||
#ifdef _MSC_VER // MSVC
|
|
||||||
constexpr std::size_t bufsize = 256;
|
|
||||||
std::array<char, bufsize> buf;
|
|
||||||
buf.fill('\0');
|
|
||||||
const auto result = strerror_s(buf.data(), bufsize, errnum);
|
|
||||||
if(result != 0)
|
|
||||||
{
|
|
||||||
return std::string("strerror_s failed");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return std::string(buf.data());
|
|
||||||
}
|
|
||||||
#elif defined(_GNU_SOURCE) && !(defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200112L )
|
|
||||||
constexpr std::size_t bufsize = 256;
|
|
||||||
std::array<char, bufsize> buf;
|
|
||||||
buf.fill('\0');
|
|
||||||
const char* result = strerror_r(errnum, buf.data(), bufsize);
|
|
||||||
return std::string(result);
|
|
||||||
#elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) || ( defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200112L ) // macOS
|
|
||||||
constexpr std::size_t bufsize = 256;
|
|
||||||
std::array<char, bufsize> buf;
|
|
||||||
buf.fill('\0');
|
|
||||||
const int result = strerror_r(errnum, buf.data(), bufsize);
|
|
||||||
if (result != 0)
|
|
||||||
{
|
|
||||||
return std::string("strerror_r failed");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return std::string(buf.data());
|
|
||||||
}
|
|
||||||
#else // fallback
|
|
||||||
return std::strerror(errnum);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
} // detail
|
|
||||||
|
|
||||||
struct file_io_error : public std::runtime_error
|
struct file_io_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
file_io_error(int errnum, const std::string& msg, const std::string& fname)
|
file_io_error(int errnum, const std::string& msg, const std::string& fname)
|
||||||
: std::runtime_error(msg + " \"" + fname + "\": " + detail::str_error(errnum)),
|
: std::runtime_error(msg + " \"" + fname + "\": errno = " + std::to_string(errnum)),
|
||||||
errno_(errnum)
|
errno_(errnum)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
int get_errno() const noexcept {return errno_;}
|
int get_errno() const noexcept {return errno_;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user