summaryrefslogtreecommitdiff
path: root/src/mbgl/util/io.cpp
diff options
context:
space:
mode:
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);
+ }
+}
+
+}
+}