diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 06a20e736..7cafc55de 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -126,21 +127,14 @@ geojson_datasource::geojson_datasource(parameters const& params) } else { -#ifdef _WINDOWS - std::unique_ptr file(_wfopen(mapnik::utf8_to_utf16(filename_).c_str(), L"rb"), fclose); -#else - std::unique_ptr file(std::fopen(filename_.c_str(),"rb"), std::fclose); -#endif - if (file == nullptr) + mapnik::util::file file(filename_); + if (!file.open()) { - throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'"); + throw mapnik::datasource_exception("TopoJSON Plugin: could not open: '" + filename_ + "'"); } - std::fseek(file.get(), 0, SEEK_END); - std::size_t file_size = std::ftell(file.get()); - std::fseek(file.get(), 0, SEEK_SET); std::string file_buffer; - file_buffer.resize(file_size); - std::fread(&file_buffer[0], file_size, 1, file.get()); + file_buffer.resize(file.size()); + std::fread(&file_buffer[0], file.size(), 1, file.get()); parse_geojson(file_buffer); } } diff --git a/plugins/input/topojson/topojson_datasource.cpp b/plugins/input/topojson/topojson_datasource.cpp index 68c3e7f6e..341390902 100644 --- a/plugins/input/topojson/topojson_datasource.cpp +++ b/plugins/input/topojson/topojson_datasource.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include using mapnik::datasource; @@ -170,21 +171,14 @@ topojson_datasource::topojson_datasource(parameters const& params) } else { -#ifdef _WINDOWS - std::unique_ptr file(_wfopen(mapnik::utf8_to_utf16(filename_).c_str(), L"rb"), fclose); -#else - std::unique_ptr file(std::fopen(filename_.c_str(),"rb"), std::fclose); -#endif - if (file == nullptr) + mapnik::util::file file(filename_); + if (!file.open()) { throw mapnik::datasource_exception("TopoJSON Plugin: could not open: '" + filename_ + "'"); } - std::fseek(file.get(), 0, SEEK_END); - std::size_t file_size = std::ftell(file.get()); - std::fseek(file.get(), 0, SEEK_SET); std::string file_buffer; - file_buffer.resize(file_size); - std::fread(&file_buffer[0], file_size, 1, file.get()); + file_buffer.resize(file.size()); + std::fread(&file_buffer[0], file.size(), 1, file.get()); parse_topojson(file_buffer); } }