diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-12-04 18:29:42 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-12-04 20:02:50 +0100 |
commit | abafb52f37beb5659efc2105ccd1568e1f754898 (patch) | |
tree | 6a60636d3497560ca61e5aae5f6d7061c4f18553 /src/mbgl/util/io.cpp | |
parent | bff6aeb4da41dee1f5f1cfa0be81b6c257257253 (diff) | |
download | qtlocation-mapboxgl-abafb52f37beb5659efc2105ccd1568e1f754898.tar.gz |
make most headers private
Diffstat (limited to 'src/mbgl/util/io.cpp')
-rw-r--r-- | src/mbgl/util/io.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mbgl/util/io.cpp b/src/mbgl/util/io.cpp new file mode 100644 index 0000000000..76f7c35ade --- /dev/null +++ b/src/mbgl/util/io.cpp @@ -0,0 +1,34 @@ +#include <mbgl/util/io.hpp> + +#include <cstdio> +#include <iostream> +#include <sstream> +#include <fstream> +#include <stdexcept> + +namespace mbgl { +namespace util { + +void write_file(const std::string &filename, const std::string &data) { + FILE *fd = fopen(filename.c_str(), "wb"); + if (fd) { + fwrite(data.data(), sizeof(std::string::value_type), data.size(), fd); + fclose(fd); + } else { + throw std::runtime_error(std::string("Failed to open file ") + filename); + } +} + +std::string read_file(const std::string &filename) { + std::ifstream file(filename); + if (file.good()) { + std::stringstream data; + data << file.rdbuf(); + return data.str(); + } else { + throw std::runtime_error(std::string("Cannot read file ") + filename); + } +} + +} +} |