summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/FileUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/Common/Src/FileUtil.cpp')
-rw-r--r--Source/Core/Common/Src/FileUtil.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp
index fada9db8e8..05030deb59 100644
--- a/Source/Core/Common/Src/FileUtil.cpp
+++ b/Source/Core/Common/Src/FileUtil.cpp
@@ -601,4 +601,35 @@ const char *GetUserDirectory()
return path;
}
+bool WriteStringToFile(bool text_file, const char *str, const char *filename)
+{
+ FILE *f = fopen(filename, text_file ? "w" : "wb");
+ if (!f)
+ return false;
+ size_t len = strlen(str);
+ if (len != fwrite(str, 1, strlen(str), f))
+ {
+ fclose(f);
+ return false;
+ }
+ fclose(f);
+ return true;
+}
+
+bool ReadStringFromFile(bool text_file, const char *filename, std::string *str)
+{
+ FILE *f = fopen(filename, text_file ? "r" : "rb");
+ if (!f)
+ return false;
+ fseek(f, 0, SEEK_END);
+ size_t len = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ char *buf = new char[len + 1];
+ buf[fread(buf, 1, len, f)] = 0;
+ *str = std::string(buf);
+ fclose(f);
+ delete [] buf;
+ return true;
+}
+
} // namespace