shithub: mc

Download patch

ref: d21343766fc75075e9246b386b60e264bfd1860e
parent: 36b4210be2a5d51607ba614d08e8369b19ca1e65
author: Ori Bernstein <ori@eigenstate.org>
date: Thu May 5 18:18:24 EDT 2016

Add nanosleep.

--- a/lib/std/syswrap-ss+osx.myr
+++ b/lib/std/syswrap-ss+osx.myr
@@ -5,11 +5,33 @@
 use "die"
 
 pkg std =
+	const nanosleep	: (nsecs : uint64 -> errno)
 	$noret const exit	: (status:int -> void)
+
 	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
 ;;
 
-const exit	= {status;	sys.exit(status)}
+
+extern const put	: (fmt : byte[:], args : ... -> int64)
+
+const nanosleep	= {nsecs
+	var s, us
+
+	s = nsecs / 1_000_000_000
+	us = (nsecs % 1_000_000_000 / 1000) castto(uint32)
+	-> sys.select( \
+		0, \
+		0 castto(sys.fdset#), \
+		0 castto(sys.fdset#), \
+		0 castto(sys.fdset#), \
+		&[.sec = s, .usec = us] \
+	) castto(errno)
+}
+
+const exit	= {status;
+	sys.exit(status)
+}
+
 const bgetcwd	= {buf
 	var path : byte[sys.Maxpathlen]
 	var fd, len, err
--- a/lib/sys/sys+osx-x64.myr
+++ b/lib/sys/sys+osx-x64.myr
@@ -17,6 +17,10 @@
 	type fcntlcmd	= int64
 	type machport	= int32
 
+	type fdset = struct
+		bits	: int32[1024/4]
+	;;
+
 	type timespec = struct
 		sec	: uint64
 		nsec	: uint32
@@ -718,6 +722,8 @@
 	const dup2	: (src : fd, dst : fd -> fd)
 	/* NB: the C ABI uses '...' for the args. */
 	const fcntl	: (fd : fd, cmd : fcntlcmd, args : byte# -> int64)
+	const poll	: (pfd : pollfd[:], tm : int -> int)
+	const select	: (nfd : int32, readfd : fdset#, writefd : fdset#, errfd : fdset#, tm : timeval# -> int32)
 
 	/* kqueue */
 	const kqueue	: (-> fd)
@@ -875,6 +881,8 @@
 const dup 	= {fd;	-> syscall(Sysdup, a(fd)) castto(fd)}
 const dup2 	= {src, dst;	-> syscall(Sysdup2, a(src), a(dst)) castto(fd)}
 const fcntl	= {fd, cmd, args; 	-> syscall(Sysfcntl, a(fd), a(cmd), a(args))}
+const poll	= {pfd, tm;	-> syscall(Syspoll, pfd castto(byte#), a(pfd.len), a(tm)) castto(int)}
+const select	= {nfd, readfd, writefd, errfd, tm; -> syscall(Sysselect, a(nfd), a(readfd), a(writefd), a(errfd), a(tm)) castto(int32)}
 
 /* kqueueueueueueue */
 const kqueue	= {;	-> syscall(Syskqueue) castto(fd)}