ref: 0d48d7452acbf58b5ec4ae22368eaaa5745fadef
parent: 84d4511320ac7ca25acb9d5ca449d5a0fcb1f246
author: Ori Bernstein <[email protected]>
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)
}