shithub: mc

Download patch

ref: cd04b272ed6045fcdac8c04f41c8d87840665a61
parent: 9fa17d0d5433dba1a65f5d52eb24b09a5092bf58
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Dec 28 20:29:40 EST 2014

Wrap posixy syscall stuff up so we can make it more portable.

--- a/libstd/bldfile
+++ b/libstd/bldfile
@@ -62,7 +62,8 @@
 	strjoin.myr
 	strsplit.myr
 	strstrip.myr
-        syswrap.myr
+        syswrap+plan9.myr
+	syswrap+posixy.myr
 	swap.myr
 	try.myr
 	types.myr
--- a/libstd/sys+linux-x64.myr
+++ b/libstd/sys+linux-x64.myr
@@ -561,6 +561,7 @@
 	const write	: (fd:fd, buf:byte[:] -> size)
 	const lseek	: (fd:fd, off:off, whence:whence -> int64)
 	const stat	: (path:byte[:], sb:statbuf# -> int64)
+	const access	: (path : byte[:], mode : accessmode -> int64)
 	const lstat	: (path:byte[:], sb:statbuf# -> int64)
 	const fstat	: (fd:fd, sb:statbuf# -> int64)
 	const mkdir	: (path : byte[:], mode : int64	-> int64)
--- a/libstd/syswrap+posixy.myr
+++ b/libstd/syswrap+posixy.myr
@@ -1,5 +1,6 @@
 use sys
 use "types.use"
+use "option.use"
 
 pkg std =
 	type fd		= sys.fd
@@ -9,9 +10,9 @@
 
 	const Failmem	: byte#	= -1 castto(byte#)
 
-	const Seekset	: whence = 0
-	const Seekcur	: whence = 1
-	const Seekend	: whence = 2
+	const Seekset	: whence = sys.Seekset	castto(whence)
+	const Seekcur	: whence = sys.Seekcur	castto(whence)
+	const Seekend	: whence = sys.Seekend	castto(whence)
 
 	const Ordonly  	: fdopt = sys.Ordonly	castto(fdopt)
 	const Owronly  	: fdopt = sys.Owronly	castto(fdopt)
@@ -33,12 +34,14 @@
 	const dup2	: (ofd : fd, nfd : fd -> fd)
 
 	/* useful/portable bits of stat */
-	const mtime	: (f : byte[:]	-> time)
-	const fsize	: (f : byte[:]	-> off)
+	const fmtime	: (f : byte[:]	-> option(time))
+	const fsize	: (f : byte[:]	-> option(off))
 
+	/* useful/portable bits of uname */
+
 	/* path manipulation */
 	const mkdir	: (path : byte[:], mode : int64 -> int64)
-	const unlink	: (path : byte[:] -> int)
+	const remove	: (path : byte[:] -> bool)
 
 	/* process stuff */
 	const getpid	: ( -> pid)
@@ -67,7 +70,7 @@
 
 /* path manipulation */
 const mkdir	= {path, mode;	-> sys.mkdir(path, mode)}
-const unlink	= {path;	-> sys.unlink(path)}
+const remove	= {path;	-> sys.unlink(path) == 0}
 
 /* process stuff */
 const getpid	= {;		-> sys.getpid() castto(pid)}
@@ -96,13 +99,19 @@
 const mtime = {path
 	var sb
 
-	sys.stat(path, &sb)
-	-> (sb.mtime.sec*1_000 + sb.mtime.nsec/1_000_000) castto(time)
+	if sys.stat(path, &sb) == 0
+		-> `Some ((sb.mtime.sec*1_000 + sb.mtime.nsec/1_000_000) castto(time))
+	else
+		-> `None
+	;;
 }
 
 const fsize = {path
 	var sb
 
-	sys.stat(path, &sb)
-	-> sb.size castto(off)
+	if sys.stat(path, &sb) == 0
+		-> `Some (sb.size castto(off))
+	else
+		-> `None
+	;;
 }