ref: b91f9a20e3c35f4328c77130fc30537f23e794d3
parent: 06fc25275fb97aec1e46467138330b202a6e3313
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 4 08:56:08 EST 2015
Fix broken stat. We were missing a return statement.
--- a/libstd/sys+plan9-x64.myr
+++ b/libstd/sys+plan9-x64.myr
@@ -158,6 +158,8 @@
const brk_ : (endp : byte# -> int64)
const nsec : (-> uint64)
+ extern const alloca : (sz : size -> byte#)
+
extern var tosptr : tos#
extern var curbrk : byte#
;;
@@ -202,7 +204,7 @@
const segflush = {va, len; -> syscall(Syssegfree, a(va), a(len))}
const unmount = {name, old; -> syscall(Sysunmount, cstring(name), cstring(old))}
const errstr = {buf; -> syscall(Syserrstr, p(buf), a(buf.len))}
-const stat = {name, edir; -> syscall(Sysstat, cstring(name), p(edir), a(edir.len))}
+const stat = {name, edir; -> syscall(Sysstat, cstring(name), p(edir), a(edir.len)) & 0xfffffff}
const fstat = {fd, edir; -> syscall(Sysstat, a(fd), p(edir), a(edir.len))}
const wstat = {name, edir; -> syscall(Syswstat, cstring(name), p(edir), a(edir.len))}
const fwstat = {fd, edir; -> syscall(Sysfwstat, a(fd), p(edir), a(edir.len))}
--- a/libstd/syswrap+plan9.myr
+++ b/libstd/syswrap+plan9.myr
@@ -71,25 +71,21 @@
/* statbuf offsets */
pkglocal const Sizeoff : int64 = 0
- pkglocal const Typeoff : int64 = Sizeoff + 2
- pkglocal const Devoff : int64 = Typeoff + 2
- pkglocal const Qidtypeoff : int64 = Devoff + 4
- pkglocal const Qidversoff : int64 = Qidtypeoff + 1
- pkglocal const Qidpathoff : int64 = Qidversoff + 4
- pkglocal const Modeoff : int64 = Qidpathoff + 8
- pkglocal const Atimeoff : int64 = Modeoff + 4
- pkglocal const Mtimeoff : int64 = Atimeoff + 4
- pkglocal const Lengthoff : int64 = Mtimeoff + 4
- pkglocal const Stringsoff : int64 = Lengthoff + 8
+ pkglocal const Typeoff : int64 = 2
+ pkglocal const Devoff : int64 = 4
+ pkglocal const Qidtypeoff : int64 =8
+ pkglocal const Qidversoff : int64 = 9
+ pkglocal const Qidpathoff : int64 = 13
+ pkglocal const Modeoff : int64 = 21
+ pkglocal const Atimeoff : int64 = 25
+ pkglocal const Mtimeoff : int64 = 29
+ pkglocal const Lengthoff : int64 = 31
+ pkglocal const Stringsoff : int64 = 39
;;
/* UGLY: circular dependency breaking... */
extern const getenvv : (name : byte[:], default : byte[:] -> byte[:])
-
-
-const Statprefixsz = Stringsoff
-
/* fd stuff */
const open = {path, opts; -> sys.open(path, opts castto(sys.fdopt)) castto(fd)}
const openmode = {path, opts, mode;
@@ -115,21 +111,21 @@
}
const fmtime = {path
- var buf : byte[Statprefixsz + 512] /* enough space for some strings */
+ var buf : byte[Stringsoff + 512] /* enough space for some strings */
- if sys.stat(path, buf[:]) < Statprefixsz
+ if sys.stat(path, buf[:]) < Stringsoff
-> `None
;;
- `Some getle32(buf[Mtimeoff:Lengthoff])
+ -> `Some getle64(buf[Lengthoff:Lengthoff + 8])
}
const fsize = {path
- var buf : byte[Statprefixsz + 512] /* enough space for some strings */
+ var buf : byte[Stringsoff + 512] /* enough space for some strings */
- if sys.stat(path, buf[:]) < Statprefixsz
+ if sys.stat(path, buf[:]) < Stringsoff
-> `None
;;
- `Some getle64(buf[Lengthoff:Stringsoff])
+ -> `Some getle64(buf[Lengthoff:Lengthoff + 8])
}
const getsysinfo = {si
@@ -221,6 +217,10 @@
-> errbuf[:i]
}
+const statsz = {buf
+ -> (buf[0] castto(int64)) | ((buf[1] << 8) castto(int64))
+}
+
const getle32 = {buf
-> (buf[0] castto(int32)) \
| ((buf[1] castto(int32)) << 8) \
@@ -229,12 +229,12 @@
}
const getle64 = {buf
- -> (buf[0] castto(int32)) \
- | ((buf[1] castto(int32)) << 8) \
- | ((buf[2] castto(int32)) << 16) \
- | ((buf[3] castto(int32)) << 24) \
- | ((buf[4] castto(int32)) << 32) \
- | ((buf[5] castto(int32)) << 40) \
- | ((buf[6] castto(int32)) << 48) \
- | ((buf[7] castto(int32)) << 56)
+ -> (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)
}