mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
fix: use fs::path, not fs::path::string() result
This commit is contained in:
@@ -2431,24 +2431,28 @@ basic_value<Comment, Table, Array>
|
|||||||
parse(FILE * file, const std::string& fname)
|
parse(FILE * file, const std::string& fname)
|
||||||
{
|
{
|
||||||
const long beg = std::ftell(file);
|
const long beg = std::ftell(file);
|
||||||
if (beg == -1l) {
|
if (beg == -1l)
|
||||||
|
{
|
||||||
throw file_io_error(errno, "Failed to access", fname);
|
throw file_io_error(errno, "Failed to access", fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = std::fseek(file, 0, SEEK_END);
|
const int res_seekend = std::fseek(file, 0, SEEK_END);
|
||||||
if (res != 0) {
|
if (res_seekend != 0)
|
||||||
|
{
|
||||||
throw file_io_error(errno, "Failed to seek", fname);
|
throw file_io_error(errno, "Failed to seek", fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const long end = std::ftell(file);
|
const long end = std::ftell(file);
|
||||||
if (end == -1l) {
|
if (end == -1l)
|
||||||
|
{
|
||||||
throw file_io_error(errno, "Failed to access", fname);
|
throw file_io_error(errno, "Failed to access", fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto fsize = end - beg;
|
const auto fsize = end - beg;
|
||||||
|
|
||||||
res = std::fseek(file, beg, SEEK_SET);
|
const auto res_seekbeg = std::fseek(file, beg, SEEK_SET);
|
||||||
if (res != 0) {
|
if (res_seekbeg != 0)
|
||||||
|
{
|
||||||
throw file_io_error(errno, "Failed to seek", fname);
|
throw file_io_error(errno, "Failed to seek", fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2488,7 +2492,8 @@ basic_value<Comment, Table, Array> parse(std::string fname)
|
|||||||
std::ifstream ifs(fname, std::ios_base::binary);
|
std::ifstream ifs(fname, std::ios_base::binary);
|
||||||
if(!ifs.good())
|
if(!ifs.good())
|
||||||
{
|
{
|
||||||
throw std::ios_base::failure("toml::parse: Error opening file \"" + fname + "\"");
|
throw std::ios_base::failure(
|
||||||
|
"toml::parse: Error opening file \"" + fname + "\"");
|
||||||
}
|
}
|
||||||
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
return parse<Comment, Table, Array>(ifs, std::move(fname));
|
return parse<Comment, Table, Array>(ifs, std::move(fname));
|
||||||
@@ -2517,7 +2522,14 @@ template<typename Comment = TOML11_DEFAULT_COMMENT_STRATEGY,
|
|||||||
template<typename ...> class Array = std::vector>
|
template<typename ...> class Array = std::vector>
|
||||||
basic_value<Comment, Table, Array> parse(const std::filesystem::path& fpath)
|
basic_value<Comment, Table, Array> parse(const std::filesystem::path& fpath)
|
||||||
{
|
{
|
||||||
return parse<Comment, Table, Array>(fpath.string());
|
std::ifstream ifs(fpath, std::ios_base::binary);
|
||||||
|
if(!ifs.good())
|
||||||
|
{
|
||||||
|
throw std::ios_base::failure(
|
||||||
|
"toml::parse: Error opening file \"" + fpath.string() + "\"");
|
||||||
|
}
|
||||||
|
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
return parse<Comment, Table, Array>(ifs, std::move(fpath.string()));
|
||||||
}
|
}
|
||||||
#endif // TOML11_HAS_STD_FILESYSTEM
|
#endif // TOML11_HAS_STD_FILESYSTEM
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user