shithub: mc

Download patch

ref: 15127e35827c55fcb3310e8b71351bd4420b2b0d
parent: 2c4ac1330705a7358cd9946ac5af3308ba1cef23
author: Ori Bernstein <[email protected]>
date: Wed Mar 2 17:34:18 EST 2016

Fix several openbsd syscalls.

--- a/lib/std/dir+openbsd.myr
+++ b/lib/std/dir+openbsd.myr
@@ -1,12 +1,13 @@
 use sys
 
-use "alloc.use"
-use "die.use"
-use "option.use"
-use "result.use"
-use "slcp.use"
-use "sldup.use"
-use "types.use"
+use "alloc"
+use "die"
+use "memops"
+use "option"
+use "result"
+use "slcp"
+use "sldup"
+use "types"
 
 pkg std =
 	type dir = struct
@@ -14,7 +15,6 @@
 		buf	: byte[16384]
 		len	: int64
 		off	: int64
-		base	: int64
 	;;
 
 	const diropen	: (p : byte[:] -> std.result(dir#, byte[:]))
@@ -38,9 +38,10 @@
 const dirread = {d
 	var len
 	var dent
+	var namelen
 
 	if d.off >= d.len
-		len = sys.getdirentries(d.fd, d.buf[:], &d.base)
+		len = sys.getdents(d.fd, d.buf[:])
 		if len <= 0
 			-> `None
 		;;
@@ -49,8 +50,12 @@
 	;;
 
 	dent = &d.buf[d.off] castto(sys.dirent#)
+	namelen = 0
 	d.off += dent.reclen castto(int64)
-	-> `Some sldup(dent.name[:dent.namelen])
+	while dent.name[namelen] != 0
+		namelen++
+	;;
+	-> `Some sldup(dent.name[:namelen])
 }
 
 const dirclose = {d
--- a/lib/std/syswrap-ss+openbsd.myr
+++ b/lib/std/syswrap-ss+openbsd.myr
@@ -5,20 +5,12 @@
 use "die.use"
 
 pkg std =
-	const exit	: (status:int -> void)
+	$noret const exit	: (status:int -> void)
 	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
 ;;
 
 const exit	= {status;	sys.exit(status)}
-const bgetcwd	= {buf
-	var res
 
-	res = sys.__getcwd(buf) castto(errno)
-	if res == 0
-		-> cstrlen(buf) castto(errno)
-	elif res == Enomem
-		-> Erange
-	else
-		-> res
-	;;
+const bgetcwd	= {buf
+	-> sys.__getcwd(buf) castto(errno)
 }
--- a/lib/sys/sys+openbsd-x64.myr
+++ b/lib/sys/sys+openbsd-x64.myr
@@ -69,9 +69,9 @@
 
 	type statbuf = struct
 		dev	: uint32 
-		ino	: uint32 
+		ino	: uint64
 		mode	: filemode
-		nlink	: uint16
+		nlink	: uint32
 		uid	: uint32
 		gid	: uint32
 		rdev	: uint32
@@ -118,6 +118,12 @@
 		scope	: uint32
 	;;
 
+	type sockaddr_un = struct
+		len	: uint8
+		fam	: sockfam
+		path	: byte[104]
+	;;
+
 	type sockaddr_storage = struct
 		len	: byte
 		fam	: sockfam
@@ -127,12 +133,13 @@
 	;;	
 	
 	type dirent = struct
-		fileno	: uint32
+		fileno	: uint64
+		off	: uint64
 		reclen	: uint16
-		ftype	: filetype
-		namelen	: uint8
+		ftype	: uint8
+		namlen	: uint8
 		name	: byte[256]	
-	;;	
+	;;
 
 	type rtprio = struct
 		rttype	: uint16
@@ -500,12 +507,6 @@
 	/* wrappers to extract wait status */
 	const waitstatus	: (st : int32 -> waitstatus)
 
-	/* thread control */
-	const thr_new	: (param : thrparam#, paramsz : int -> int)
-	const thr_exit	: (state : int64# -> void)
-	const umtx_op	: (obj : void#, op : umtxop, val : uint64, a1 : void#, a2 : void# -> int)
-	const yield	: (-> int)
-
 	/* fd manipulation */
 	const open	: (path:byte[:], opts:fdopt -> fd)
 	const openmode	: (path:byte[:], opts:fdopt, mode:int64 -> fd)
@@ -520,7 +521,7 @@
 	const fstat	: (fd:fd, sb:statbuf# -> int64)
 	const mkdir	: (path : byte[:], mode : int64	-> int64)
 	generic ioctl	: (fd:fd, req : int64, arg:@a# -> int64)
-	const getdirentries	: (fd : fd, buf : byte[:], basep : int64# -> int64)
+	const getdents	: (fd : fd, buf : byte[:] -> int64)
 	const chdir	: (p : byte[:] -> int64)
 	const __getcwd	: (buf : byte[:] -> int64)
 
@@ -621,13 +622,6 @@
 	-> syscall(Sysexecve, cstring(cmd), a(p), a(cenv))
 }
 
-/* thread management */
-
-const thr_new	= {param, sz;	-> -1}
-const thr_exit	= {state;	-> void}
-const umtx_op	= {obj, op, val, a1, a2; -> -1}
-const yield	= {;	-> -1}
-
 /* fd manipulation */
 const open	= {path, opts;		-> syscall(Sysopen, cstring(path), a(opts), a(0o777)) castto(fd)}
 const openmode	= {path, opts, mode;	-> syscall(Sysopen, cstring(path), a(opts), a(mode)) castto(fd)}
@@ -641,11 +635,10 @@
 const lstat	= {path, sb;		-> syscall(Syslstat, cstring(path), a(sb))}
 const fstat	= {fd, sb;		-> syscall(Sysfstat, a(fd), a(sb))}
 const mkdir	= {path, mode;		-> syscall(Sysmkdir, cstring(path), a(mode)) castto(int64)}
-generic ioctl	= {fd, req, arg;	-> syscall(Sysioctl, a(fd), a(req), a(arg)) castto(int64)
-}
-const getdirentries	= {fd, buf, basep;	-> -1}
+generic ioctl	= {fd, req, arg;	-> syscall(Sysioctl, a(fd), a(req), a(arg)) castto(int64)}
 const chdir	= {dir;	-> syscall(Syschdir, cstring(dir))}
 const __getcwd	= {buf;	-> syscall(Sys__getcwd, a(buf), a(buf.len))}
+const getdents	= {fd, buf;		-> syscall(Sysgetdents, a(buf), a(buf.len)) castto(int64)}
 
 /* file stuff */
 const pipe	= {fds;	-> __freebsd_pipe(fds)}
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -386,7 +386,7 @@
 	;;
 	std.fput(std.Err, "could not find library {}\n", lib)
 
-	:error
+:error
 	std.fput(std.Err, "search path is:\n")
 	for p in incs
 		std.fput(std.Err, "\t{}\n", p)