shithub: mc

Download patch

ref: 1f57c415f58c7d9f102714d8ec1385d26b6ec8ed
parent: 1aaecac7967767bd585349befe06b2a4beb31d22
author: Ori Bernstein <[email protected]>
date: Thu Jun 19 16:56:49 EDT 2014

Add support for directory listing under OSX

--- a/libstd/dir-osx.myr
+++ b/libstd/dir-osx.myr
@@ -1,0 +1,60 @@
+use "alloc.use"
+use "die.use"
+use "option.use"
+use "result.use"
+use "slcp.use"
+use "sldup.use"
+use "sys.use"
+use "types.use"
+
+pkg std =
+	type dir = struct
+		fd	: fd
+		buf	: byte[16384]
+		len	: int64
+		off	: int64
+		base	: int64
+	;;
+
+	const diropen	: (p : byte[:] -> std.result(dir#, byte[:]))
+	const dirread	: (d : dir# -> std.option(byte[:]))
+	const dirclose	: (d : dir# -> void)
+;;
+
+const diropen = {p
+	var fd
+	var dir
+
+	fd = open(p, Ordonly | Odir)
+	if fd < 0
+		-> `Fail "couldn't open directory"
+	;;
+	dir = zalloc()
+	dir.fd = fd
+	-> `Ok dir
+}
+
+const dirread = {d
+	var len
+	var dent
+	var namelen
+
+	if d.off >= d.len
+		len = getdirentries64(d.fd, d.buf[:], &d.base)
+		if len <= 0
+			-> `None
+		;;
+		d.len = len
+		d.off = 0
+	;;
+
+	dent = &d.buf[d.off] castto(dirent64#)
+	d.off += dent.reclen castto(int64)
+	-> `Some sldup(dent.name[:dent.namlen])
+}
+
+const dirclose = {d
+	close(d.fd)
+	free(d)
+}
+
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -99,7 +99,7 @@
 		reclen	: uint16	/* length of this record */
 		namlen	: uint16	/* length of string in d_name */
 		typeid  : uint8		/* file type, see below */
-		name	: byte[1024]
+		name	: byte[0]
 	;;
 
 	/* open options */