shithub: mc

Download patch

ref: 11be53a01c3112de8fd6bcf81b306ee7c39a37ec
parent: f2afc8da2339dbfaaa7dd92abf63521ae38e6dd8
author: Ori Bernstein <[email protected]>
date: Wed Aug 7 09:54:29 EDT 2013

Add an 'fd' type.

--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -9,6 +9,7 @@
     optparse.myr \
     rand.myr \
     slappend.myr \
+    slcp.myr \
     sleq.myr \
     slurp.myr \
     sys.myr \
--- a/libstd/sys-linux.myr
+++ b/libstd/sys-linux.myr
@@ -1,10 +1,12 @@
 use "types.use"
 
 pkg std =
-	type scno = int64
-	type fdopt = int64
-	type mprot = int64
-	type mopt = int64
+	type scno	= int64
+	type fdopt	= int64
+	type mprot	= int64
+	type mopt	= int64
+	type fd	= int64
+
 	type statbuf = struct
 		 dev     : uint
 		 ino     : uint
@@ -374,23 +376,26 @@
 	const exit	: (status:int -> void)
 	const getpid	: ( -> int64)
 	const kill	: (pid:int64, sig:int64 -> int64)
-	const open	: (path:byte[:], opts:fdopt, mode:int64 -> int64)
-	const close	: (fd:int64 -> int64)
-	const creat	: (path:byte[:], mode:int64 -> int64)
-	const read	: (fd:int64, buf:byte[:] -> size)
-	const write	: (fd:int64, buf:byte[:] -> size)
-	const lseek	: (fd:int64, off:uint64, whence:int64 -> int64)
-	const fstat	: (fd:int64, sb:statbuf# -> int64)
+
+	/* fd manipulation */
+	const open	: (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 lseek	: (fd:fd, off:uint64, whence:int64 -> int64)
+	const fstat	: (fd:fd, sb:statbuf# -> int64)
+
 	const munmap	: (addr:byte#, len:size -> int64)
-	const mmap	: (addr:byte#, len:size, prot:mprot, flags:mopt, fd:int64, off:off -> byte#)
+	const mmap	: (addr:byte#, len:size, prot:mprot, flags:mopt, fd:fd, off:off -> byte#)
 ;;
 
 const exit	= {status;		syscall(Sysexit, status castto(int64))}
 const getpid	= {;			-> syscall(Sysgetpid, 1)}
 const kill	= {pid, sig;		-> syscall(Syskill, pid, sig)}
-const open	= {path, opts, mode;	-> syscall(Sysopen, cstring(path), opts, mode)}
+const open	= {path, opts, mode;	-> syscall(Sysopen, cstring(path), opts, mode) castto(fd)}
 const close	= {fd;			-> syscall(Sysclose, fd)}
-const creat	= {path, mode;		-> syscall(Syscreat, cstring(path), mode)}
+const creat	= {path, mode;		-> syscall(Syscreat, cstring(path), mode) castto(fd)}
 const read	= {fd, buf;		-> syscall(Sysread, fd, buf castto(byte#), buf.len castto(size)) castto(size)}
 const write	= {fd, buf;		-> syscall(Syswrite, fd, buf castto(byte#), buf.len castto(size)) castto(size)}
 const lseek	= {fd, off, whence;	-> syscall(Syslseek, fd, off, whence)}
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -5,6 +5,7 @@
 	type fdopt = int64
 	type mprot = int64
 	type mopt = int64
+	type fd = int64
 
 	type timespec = struct
 		secs	: uint64
@@ -420,23 +421,25 @@
 	const exit	: (status:int -> void)
 	const getpid	: ( -> int64)
 	const kill	: (pid:int64, sig:int64 -> int64)
-	const open	: (path:byte[:], opts:fdopt, mode:int64 -> int64)
-	const close	: (fd:int64 -> int64)
-	const creat	: (path:byte[:], mode:int64 -> int64)
-	const read	: (fd:int64, buf:byte[:] -> size)
-	const write	: (fd:int64, buf:byte[:] -> size)
-	const lseek	: (fd:int64, off:uint64, whence:int64 -> int64)
-	const fstat	: (fd:int64, sb:statbuf# -> int64)
+
+	const open	: (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 lseek	: (fd:fd, off:uint64, whence:int64 -> int64)
+	const fstat	: (fd:fd, sb:statbuf# -> int64)
+
 	const munmap	: (addr:byte#, len:size -> int64)
-	const mmap	: (addr:byte#, len:size, prot:mprot, flags:mopt, fd:int64, off:off -> byte#)
+	const mmap	: (addr:byte#, len:size, prot:mprot, flags:mopt, fd:fd, off:off -> byte#)
 ;;
 
 const exit	= {status;		syscall(Sysexit, status castto(int64))}
 const getpid	= {;			-> syscall(Sysgetpid, 1)}
 const kill	= {pid, sig;		-> syscall(Syskill, pid, sig)}
-const open	= {path, opts, mode;	-> syscall(Sysopen, cstring(path), opts, mode)}
+const open	= {path, opts, mode;	-> syscall(Sysopen, cstring(path), opts, mode) castto(fd)}
 const close	= {fd;			-> syscall(Sysclose, fd)}
-const creat	= {path, mode;		-> open(path, Ocreat | Otrunc | Owronly, mode)}
+const creat	= {path, mode;		-> open(path, Ocreat | Otrunc | Owronly, mode) castto(fd)}
 const read	= {fd, buf;		-> syscall(Sysread, fd, buf castto(char#), buf.len castto(size)) castto(size)}
 const write	= {fd, buf;		-> syscall(Syswrite, fd, buf castto(char#), buf.len castto(size)) castto(size)}
 const lseek	= {fd, off, whence;	-> syscall(Syslseek, fd, off, whence)}