shithub: mc

Download patch

ref: 982a5bf2f128f46a3d8c814b199282435f64becb
parent: 0d48d7452acbf58b5ec4ae22368eaaa5745fadef
author: Ori Bernstein <[email protected]>
date: Sun Dec 28 20:28:50 EST 2014

syswrap+plan9 wasn't x64 specific.

--- a/libstd/syswrap+plan9-x64.myr
+++ /dev/null
@@ -1,139 +1,0 @@
-use sys
-use "types.use"
-
-pkg std =
-	type fd		= sys.fd
-	type pid	= sys.pid
-	type fdopt	= sys.fdopt
-
-	const Failmem	: byte#	= -1 castto(byte#)
-
-	const Ordonly  	: fdopt = sys.Ordonly	castto(fdopt)
-	const Owronly  	: fdopt = sys.Owronly	castto(fdopt)
-	const Ordwr    	: fdopt = sys.Ordwr	castto(fdopt)
-	const Otrunc   	: fdopt = sys.Otrunc	castto(fdopt)
-	const Ocreat   	: fdopt = 0x1000000	/* emulated by redirecting to creat(). */
-	const Oappend  	: fdopt = 0x2000000	/* emulated by seeking to EOF */
-	const Odir	: fdopt = 0x0	/* no-op on plan9 */
-
-	/* fd stuff */
-	const open	: (path : byte[:], opts : fdopt -> fd)
-	const openmode	: (path : byte[:], opts : fdopt, mode : int64 -> fd)
-	const close	: (fd : fd -> int64)
-	const creat	: (path : byte[:], mode : int64 -> fd)
-	const read	: (fd : fd, buf : byte[:] -> size)
-	const write	: (fd : fd, buf : byte[:] -> size)
-	const pipe	: (fds : fd[2]# -> int64)
-	const dup2	: (ofd : fd, nfd : fd -> fd)
-
-	/* path manipulation */
-	const mkdir	: (path : byte[:], mode : int64 -> int64)
-	const unlink	: (path : byte[:] -> int64)
-
-	/* process stuff */
-	const getpid	: ( -> pid)
-	const suicide	: ( -> void)
-	const fork	: (-> pid)
-	const execv	: (cmd : byte[:], args : byte[:][:] -> int64)
-	const execve	: (cmd : byte[:], args : byte[:][:], env : byte[:][:] -> int64)
-	const exit	: (status:int -> void)
-	const waitpid	: (pid:pid, loc:int32#, opt : int64	-> pid)
-
-	pkglocal const getmem	: (sz : size -> byte#)
-	pkglocal const freemem	: (p : byte#, sz : size -> void)
-	pkglocal const curtime	: (-> time)
-;;
-
-/* fd stuff */
-const open	= {path, opts;	-> sys.open(path, opts castto(sys.fdopt)) castto(fd)}
-const openmode	= {path, opts, mode;
-	var fd
-
-
-	if opts & Ocreat != 0
-		fd = sys.create(path, opts castto(sys.fdopt), mode castto(int))
-	else
-		fd = sys.open(path, opts castto(sys.fdopt))
-	;;
-	if opts & Oappend != 0
-		sys.seek(fd, 0, 2)
-	;;
-	-> fd castto(fd)
-}
-
-const close	= {fd;		-> sys.close(fd castto(sys.fd)) castto(int64)}
-const read	= {fd, buf;	-> sys.pread(fd castto(sys.fd), buf, -1) castto(size)}
-const write	= {fd, buf;	-> sys.pwrite(fd castto(sys.fd), buf, -1) castto(size)}
-const pipe	= {fds;		-> sys.pipe(fds castto(sys.fd[2]#)) castto(int64)}
-const dup2	= {ofd, nfd;	-> sys.dup(ofd castto(sys.fd), nfd castto(sys.fd)) castto(fd)}
-
-/* path manipulation */
-const unlink	= {path;	-> sys.remove(path)}
-const mkdir	= {path, mode;
-	var fd
-
-	fd = sys.create(path, sys.Ordonly, sys.Dmdir | (mode castto(int)))
-	if fd < 0
-		-> -1
-	;;
-	sys.close(fd)
-	-> 0
-}
-
-/* process stuff */
-const getpid	= {;	-> sys.tosptr.pid castto(pid)}
-const suicide	= {;	(0 castto(byte#))#}	/* let's happy segfault!! t */
-const fork	= {;		-> sys.rfork(sys.Rffdg | sys.Rfrend | sys.Rfproc) castto(pid)}
-const execv	= {cmd, args;	-> sys.exec(cmd, args) castto(int64)}
-const execve	= {cmd, args, env;	-> sys.exec(cmd, args) castto(int64)}
-const digitchars = "0123456789"
-const exit	= {status
-	var buf : byte[32]	/* big enough for exit status numbers */
-	var n, i
-	
-	if status == 0
-		sys.exits("")
-	else
-		status &= 255
-		i = 100
-		n = 0
-		while i > 0
-			if status >= i
-				buf[n++] = digitchars[(status/i)%10]
-			;;
-			i /= 10
-		;;
-		sys.exits(buf[:n])
-	;;
-}
-
-/* FIXME: horribly broken. We wait for a pid to exit, and lie about which one. */
-const waitpid	= {pid, loc, opt;
-	var buf : byte[512]
-	var n
-
-	loc# = 0
-	n = sys.await(buf[:])
-	-> pid
-}
-
-/* memory stuff */
-const getmem	= {sz
-	var endp, oldp
-
-	oldp = sys.curbrk
-	endp = (sys.curbrk castto(intptr)) + (sz castto(intptr))
-	if sys.brk_(endp castto(byte#)) < 0
-		-> Failmem
-	;;
-	sys.curbrk = endp castto(byte#)
-	-> oldp
-}
-	
-const freemem = {p, sz
-	/* FIXME: don't leak */
-}
-
-const curtime = {
-	-> sys.nsec()/1000 castto(time)
-}
--- /dev/null
+++ b/libstd/syswrap+plan9.myr
@@ -1,0 +1,143 @@
+use sys
+use "types.use"
+
+pkg std =
+	type fd		= sys.fd
+	type pid	= sys.pid
+	type fdopt	= sys.fdopt
+
+	const Failmem	: byte#	= -1 castto(byte#)
+
+	const Ordonly  	: fdopt = sys.Ordonly	castto(fdopt)
+	const Owronly  	: fdopt = sys.Owronly	castto(fdopt)
+	const Ordwr    	: fdopt = sys.Ordwr	castto(fdopt)
+	const Otrunc   	: fdopt = sys.Otrunc	castto(fdopt)
+	const Ocreat   	: fdopt = 0x1000000	/* emulated by redirecting to creat(). */
+	const Oappend  	: fdopt = 0x2000000	/* emulated by seeking to EOF */
+	const Odir	: fdopt = 0x0	/* no-op on plan9 */
+
+	/* fd stuff */
+	const open	: (path : byte[:], opts : fdopt -> fd)
+	const openmode	: (path : byte[:], opts : fdopt, mode : int64 -> fd)
+	const close	: (fd : fd -> int64)
+	const creat	: (path : byte[:], mode : int64 -> fd)
+	const read	: (fd : fd, buf : byte[:] -> size)
+	const write	: (fd : fd, buf : byte[:] -> size)
+	const pipe	: (fds : fd[2]# -> int64)
+	const dup2	: (ofd : fd, nfd : fd -> fd)
+
+	/* useful/portable bits of stat */
+	const fmtime	: (f : byte[:]	-> option(time))
+	const fsize	: (f : byte[:]	-> option(off))
+
+	/* path manipulation */
+	const mkdir	: (path : byte[:], mode : int64 -> int64)
+	const remove	: (path : byte[:] -> bool)
+
+	/* process stuff */
+	const getpid	: ( -> pid)
+	const suicide	: ( -> void)
+	const fork	: (-> pid)
+	const execv	: (cmd : byte[:], args : byte[:][:] -> int64)
+	const execve	: (cmd : byte[:], args : byte[:][:], env : byte[:][:] -> int64)
+	const exit	: (status:int -> void)
+	const waitpid	: (pid:pid, loc:int32#, opt : int64	-> pid)
+
+	pkglocal const getmem	: (sz : size -> byte#)
+	pkglocal const freemem	: (p : byte#, sz : size -> void)
+	pkglocal const curtime	: (-> time)
+;;
+
+/* fd stuff */
+const open	= {path, opts;	-> sys.open(path, opts castto(sys.fdopt)) castto(fd)}
+const openmode	= {path, opts, mode;
+	var fd
+
+
+	if opts & Ocreat != 0
+		fd = sys.create(path, opts castto(sys.fdopt), mode castto(int))
+	else
+		fd = sys.open(path, opts castto(sys.fdopt))
+	;;
+	if opts & Oappend != 0
+		sys.seek(fd, 0, 2)
+	;;
+	-> fd castto(fd)
+}
+
+const close	= {fd;		-> sys.close(fd castto(sys.fd)) castto(int64)}
+const read	= {fd, buf;	-> sys.pread(fd castto(sys.fd), buf, -1) castto(size)}
+const write	= {fd, buf;	-> sys.pwrite(fd castto(sys.fd), buf, -1) castto(size)}
+const pipe	= {fds;		-> sys.pipe(fds castto(sys.fd[2]#)) castto(int64)}
+const dup2	= {ofd, nfd;	-> sys.dup(ofd castto(sys.fd), nfd castto(sys.fd)) castto(fd)}
+
+/* path manipulation */
+const remove	= {path;	-> sys.remove(path) == 0}
+const mkdir	= {path, mode;
+	var fd
+
+	fd = sys.create(path, sys.Ordonly, sys.Dmdir | (mode castto(int)))
+	if fd < 0
+		-> -1
+	;;
+	sys.close(fd)
+	-> 0
+}
+
+/* process stuff */
+const getpid	= {;	-> sys.tosptr.pid castto(pid)}
+const suicide	= {;	(0 castto(byte#))#}	/* let's happy segfault!! t */
+const fork	= {;		-> sys.rfork(sys.Rffdg | sys.Rfrend | sys.Rfproc) castto(pid)}
+const execv	= {cmd, args;	-> sys.exec(cmd, args) castto(int64)}
+const execve	= {cmd, args, env;	-> sys.exec(cmd, args) castto(int64)}
+const digitchars = "0123456789"
+const exit	= {status
+	var buf : byte[32]	/* big enough for exit status numbers */
+	var n, i
+	
+	if status == 0
+		sys.exits("")
+	else
+		status &= 255
+		i = 100
+		n = 0
+		while i > 0
+			if status >= i
+				buf[n++] = digitchars[(status/i)%10]
+			;;
+			i /= 10
+		;;
+		sys.exits(buf[:n])
+	;;
+}
+
+/* FIXME: horribly broken. We wait for a pid to exit, and lie about which one. */
+const waitpid	= {pid, loc, opt;
+	var buf : byte[512]
+	var n
+
+	loc# = 0
+	n = sys.await(buf[:])
+	-> pid
+}
+
+/* memory stuff */
+const getmem	= {sz
+	var endp, oldp
+
+	oldp = sys.curbrk
+	endp = (sys.curbrk castto(intptr)) + (sz castto(intptr))
+	if sys.brk_(endp castto(byte#)) < 0
+		-> Failmem
+	;;
+	sys.curbrk = endp castto(byte#)
+	-> oldp
+}
+	
+const freemem = {p, sz
+	/* FIXME: don't leak */
+}
+
+const curtime = {
+	-> sys.nsec()/1000 castto(time)
+}