feat: Add a parse(FILE *) interface

The fstream classes are notorious for their non-existent error handling.

This adds a C-style fILE * IO (fopen(), etc.) alternative interface, so
that if a user needs reliable error handling, they can use that, albeit
more inconvenient, but more robust approach.
This commit is contained in:
Lukáš Hrázký
2022-06-30 13:53:32 +02:00
parent 594accf9a7
commit bf9c9d620d
3 changed files with 146 additions and 15 deletions

View File

@@ -10,6 +10,18 @@
namespace toml
{
struct file_io_error : public std::runtime_error
{
public:
file_io_error(int errnum, const std::string& msg, const std::string& fname)
: std::runtime_error(msg + " \"" + fname + "\": " + std::strerror(errnum)),
errno_(errnum)
{}
int get_errno() {return errno_;}
private:
int errno_;
};
struct exception : public std::exception
{
public: