summaryrefslogtreecommitdiff
path: root/src/mbgl/util/io.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-12-04 18:29:42 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-12-04 20:02:50 +0100
commitabafb52f37beb5659efc2105ccd1568e1f754898 (patch)
tree6a60636d3497560ca61e5aae5f6d7061c4f18553 /src/mbgl/util/io.cpp
parentbff6aeb4da41dee1f5f1cfa0be81b6c257257253 (diff)
downloadqtlocation-mapboxgl-abafb52f37beb5659efc2105ccd1568e1f754898.tar.gz
make most headers private
Diffstat (limited to 'src/mbgl/util/io.cpp')
-rw-r--r--src/mbgl/util/io.cpp34
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);
+ }
+}
+
+}
+}