ref: e7e2e25385cd8e9dfb688bf9ae3e48728a1ddd72
parent: bccb73dc9a1d19bf472c9ce776cc6ee76cef05d5
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Feb 28 13:18:32 EST 2016
Fix Dm* constants and add fisdir
--- a/lib/std/syswrap+plan9.myr
+++ b/lib/std/syswrap+plan9.myr
@@ -6,6 +6,7 @@
use "result"
use "cstrconv"
use "strfind"
+use "getint"
pkg std =
type fd = sys.fd
@@ -48,6 +49,7 @@
const fmtime : (f : byte[:] -> result(time, errno))
const fsize : (f : byte[:] -> result(off, errno))
const fexists : (f : byte[:] -> bool)
+ const fisdir : (f : byte[:] -> bool)
/* the important bits that uname provides */
const getsysinfo : (si : sysinfo# -> void)
@@ -129,6 +131,16 @@
-> `Ok (getle64(buf[Lengthoff:Lengthoff + 8]) castto(off))
}
+extern const put : (fmt : byte[:], args : ... -> int64)
+const fisdir = {path
+ var buf : byte[Stringsoff + 39] /* enough space for qid type */
+
+ if sys.stat(path, buf[:]) < Stringsoff
+ -> false
+ ;;
+ -> (getle32(buf[Modeoff:Modeoff + 4]) & sys.Dmdir) != 0
+}
+
const getsysinfo = {si
si.system = getenvv("osname", "Plan9")
si.release = "4"
@@ -209,23 +221,6 @@
}
*/
-const getle32 = {buf
- -> (buf[0] castto(int32)) \
- | ((buf[1] castto(int32)) << 8) \
- | ((buf[2] castto(int32)) << 16) \
- | ((buf[3] castto(int32)) << 24)
-}
-
-const getle64 = {buf
- -> (buf[0] castto(int64)) \
- | ((buf[1] castto(int64)) << 8) \
- | ((buf[2] castto(int64)) << 16) \
- | ((buf[3] castto(int64)) << 24) \
- | ((buf[4] castto(int64)) << 64) \
- | ((buf[5] castto(int64)) << 40) \
- | ((buf[6] castto(int64)) << 48) \
- | ((buf[7] castto(int64)) << 56)
-}
generic check = {e : @a::(integral, numeric) -> result(@b, errno)
if e < 0
-> `Fail lasterr()
--- a/lib/sys/sys+plan9-x64.myr
+++ b/lib/sys/sys+plan9-x64.myr
@@ -45,12 +45,12 @@
const Qttmp : int = 0x04
const Qtfile : int = 0x00
- const Dmdir : int = 0x8000000
- const Dmappend : int = 0x4000000
- const Dmexcl : int = 0x2000000
- const Dmmount : int = 0x1000000
- const Dmauth : int = 0x0800000
- const Dmtmp : int = 0x0400000
+ const Dmdir : int = 0x80000000
+ const Dmappend : int = 0x40000000
+ const Dmexcl : int = 0x20000000
+ const Dmmount : int = 0x10000000
+ const Dmauth : int = 0x08000000
+ const Dmtmp : int = 0x04000000
const Dmread : int = 0x4
const Dmwrite : int = 0x2
const Dmexec : int = 0x1
--- a/mbldwrap.sh
+++ b/mbldwrap.sh
@@ -16,8 +16,8 @@
fi
if [ -f mbld/mbld ]; then
- ./mbld/mbld -S $@ || mbld -S $@ || \
+ ./mbld/mbld $@ || mbld $@ || \
(echo "Unable to run mbld $@; have you build successfully"; false)
else
- ./mbld/mbld -S || mbld -S || $BOOT
+ ./mbld/mbld || mbld || $BOOT
fi