summaryrefslogtreecommitdiffstats
path: root/src/disk_interface.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/disk_interface.cc')
-rw-r--r--src/disk_interface.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index 789f199..96a1e59 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -103,6 +103,26 @@ TimeStamp RealDiskInterface::Stat(const string& path) {
#endif
}
+bool RealDiskInterface::WriteFile(const string & path, const string & contents) {
+ FILE * fp = fopen(path.c_str(), "w");
+ if (fp == NULL) {
+ Error("WriteFile(%s): Unable to create file. %s", path.c_str(), strerror(errno));
+ return false;
+ }
+
+ if (fwrite(contents.data(), 1, contents.length(), fp) < contents.length()) {
+ Error("WriteFile(%s): Unable to write to the file. %s", path.c_str(), strerror(errno));
+ return false;
+ }
+
+ if (fclose(fp) == EOF) {
+ Error("WriteFile(%s): Unable to close the file. %s", path.c_str(), strerror(errno));
+ return false;
+ }
+
+ return true;
+}
+
bool RealDiskInterface::MakeDir(const string& path) {
if (::MakeDir(path) < 0) {
Error("mkdir(%s): %s", path.c_str(), strerror(errno));