summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-04-15 18:46:51 -0400
committerKonstantin Käfer <mail@kkaefer.com>2014-04-15 18:46:51 -0400
commit56393007f1b0b36b3f8c34bed48db6bea1da4f9f (patch)
tree3a90d53f65014e9431a771317002b1d48d867f16
parent709dfc22db0020c67b930ed61ab02ebfeedca979 (diff)
downloadqtlocation-mapboxgl-56393007f1b0b36b3f8c34bed48db6bea1da4f9f.tar.gz
add function to write files
-rw-r--r--include/llmr/util/io.hpp14
-rw-r--r--src/util/io.cpp13
2 files changed, 27 insertions, 0 deletions
diff --git a/include/llmr/util/io.hpp b/include/llmr/util/io.hpp
new file mode 100644
index 0000000000..f1e560ffe4
--- /dev/null
+++ b/include/llmr/util/io.hpp
@@ -0,0 +1,14 @@
+#ifndef LLMR_UTIL_IO
+#define LLMR_UTIL_IO
+
+#include <string>
+
+namespace llmr {
+namespace util {
+
+void write_file(const std::string &filename, const std::string &data);
+
+}
+}
+
+#endif
diff --git a/src/util/io.cpp b/src/util/io.cpp
new file mode 100644
index 0000000000..bf519b0573
--- /dev/null
+++ b/src/util/io.cpp
@@ -0,0 +1,13 @@
+#include <llmr/util/io.hpp>
+
+#include <cstdio>
+
+void llmr::util::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 {
+ fprintf(stderr, "Failed to open file\n");
+ }
+}