ref: c40bf0f7b8be2563e9641321bdabfbbd08870e23
parent: 6d8c2c169d24a7a4008803395ed9c3ca97960e90
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Dec 28 20:04:38 EST 2014
Add mtime() and fsize() calls to libstd. These should be portable enough.
--- a/libstd/syswrap+posixy.myr
+++ b/libstd/syswrap+posixy.myr
@@ -32,6 +32,10 @@
const seek : (fd : fd, delta : off, whence : whence -> off)
const dup2 : (ofd : fd, nfd : fd -> fd)
+ /* useful/portable bits of stat */
+ const mtime : (f : byte[:] -> time)
+ const fsize : (f : byte[:] -> off)
+
/* path manipulation */
const mkdir : (path : byte[:], mode : int64 -> int64)
const unlink : (path : byte[:] -> int)
@@ -87,4 +91,18 @@
else
-> -1
;;
+}
+
+const mtime = {path
+ var sb
+
+ sys.stat(path, &sb)
+ -> (sb.mtime.sec*1_000 + sb.mtime.nsec/1_000_000) castto(time)
+}
+
+const fsize = {path
+ var sb
+
+ sys.stat(path, &sb)
+ -> sb.size castto(off)
}