new fortune.
[feisty_meow.git] / nucleus / library / filesystem / huge_file.cpp
index 33b4672a2f23f50d3cbe81324e5719c02a5c32d1..f452fd30e32bb93b923ee0749bfae72a116469b0 100644 (file)
@@ -20,6 +20,7 @@
 #include <basis/guards.h>
 
 #include <stdio.h>
+#include <sys/time.h>
 
 #undef LOG
 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
@@ -42,6 +43,8 @@ huge_file::~huge_file()
   WHACK(_real_file);
 }
 
+const astring &huge_file::name() const { return _real_file->name(); }
+
 void huge_file::flush() { _real_file->flush(); }
 
 bool huge_file::truncate() { return _real_file->truncate(); }
@@ -276,5 +279,24 @@ outcome huge_file::write(const byte_array &to_write, int &size_written)
   return OKAY;
 }
 
+basis::outcome huge_file::touch()
+{
+  if (filename(_real_file->name()).exists()) {
+    // file exists, so just update time.
+    int ret = utimes(_real_file->name().observe(), NIL);
+    if (ret != 0)
+      return FAILURE;
+  } else {
+    // file doesn't exist yet.
+    byte_array junk(1);
+    int written;
+    outcome ret = write(junk, written);
+    if (ret != OKAY) ret;
+    if (!truncate())
+      return FAILURE;
+  }
+  return OKAY;
+}
+
 } //namespace.