summaryrefslogtreecommitdiffstats
path: root/src/disk_interface.cc
diff options
context:
space:
mode:
authorThiago Farina <tfarina@chromium.org>2011-08-24 00:33:41 (GMT)
committerThiago Farina <tfarina@chromium.org>2011-08-25 03:00:35 (GMT)
commit16761d7c766e0bed31e7648e3c5f2ce67c3aca52 (patch)
tree01ad64daa3d60762f8bc807eddca2eb32797971d /src/disk_interface.cc
parentb0dac493c41b228f0f725faf65590a1595e2245c (diff)
downloadNinja-16761d7c766e0bed31e7648e3c5f2ce67c3aca52.zip
Ninja-16761d7c766e0bed31e7648e3c5f2ce67c3aca52.tar.gz
Ninja-16761d7c766e0bed31e7648e3c5f2ce67c3aca52.tar.bz2
Move RealDiskInterface class to disk_interface.h.
This is a TODO in src/ninja_jumble.cc Signed-off-by: Thiago Farina <tfarina@chromium.org>
Diffstat (limited to 'src/disk_interface.cc')
-rw-r--r--src/disk_interface.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index 70564d7..6404bd5 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -14,6 +14,13 @@
#include "disk_interface.h"
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include "util.h"
+
namespace {
std::string DirName(const std::string& path) {
@@ -33,6 +40,8 @@ std::string DirName(const std::string& path) {
} // namespace
+// DiskInterface ---------------------------------------------------------------
+
bool DiskInterface::MakeDirs(const std::string& path) {
std::string dir = DirName(path);
if (dir.empty())
@@ -49,3 +58,53 @@ bool DiskInterface::MakeDirs(const std::string& path) {
return false;
return MakeDir(dir);
}
+
+// RealDiskInterface -----------------------------------------------------------
+
+int RealDiskInterface::Stat(const std::string& path) {
+ struct stat st;
+ if (stat(path.c_str(), &st) < 0) {
+ if (errno == ENOENT) {
+ return 0;
+ } else {
+ Error("stat(%s): %s", path.c_str(), strerror(errno));
+ return -1;
+ }
+ }
+
+ return st.st_mtime;
+ return true;
+}
+
+bool RealDiskInterface::MakeDir(const std::string& path) {
+ if (::MakeDir(path) < 0) {
+ Error("mkdir(%s): %s", path.c_str(), strerror(errno));
+ return false;
+ }
+ return true;
+}
+
+std::string RealDiskInterface::ReadFile(const std::string& path,
+ std::string* err) {
+ std::string contents;
+ int ret = ::ReadFile(path, &contents, err);
+ if (ret == -ENOENT) {
+ // Swallow ENOENT.
+ err->clear();
+ }
+ return contents;
+}
+
+int RealDiskInterface::RemoveFile(const std::string& path) {
+ if (remove(path.c_str()) < 0) {
+ switch (errno) {
+ case ENOENT:
+ return 1;
+ default:
+ Error("remove(%s): %s", path.c_str(), strerror(errno));
+ return -1;
+ }
+ } else {
+ return 0;
+ }
+}