summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCarlin Bingham <cb@viennan.net>2019-07-23 03:12:29 +1200
committerOri Bernstein <ori@eigenstate.org>2019-07-22 10:05:21 -0700
commitef03dd4e5de858a096e880e19eb7ed3acf857f5c (patch)
treecc9760c4fdb3411ee2ceb17254b5a0048b2521bd /lib
parenta4eb9c0aca8ae4adb6c50133ba26bbd250ae934d (diff)
downloadmc-ef03dd4e5de858a096e880e19eb7ed3acf857f5c.tar.gz
Fix std.getcwd on OpenBSD -current
The __getcwd syscall returning the length of the string was apparently unintended and was changed in 6.5 -current to return 0 on success: https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/kern/vfs_getcwd.c#rev1.33 This causes std.getcwd to return an empty string, which at least breaks `mbld test`. This patch works with both the old and new behaviour.
Diffstat (limited to 'lib')
-rw-r--r--lib/std/syswrap-ss+openbsd.myr14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/std/syswrap-ss+openbsd.myr b/lib/std/syswrap-ss+openbsd.myr
index 0f4ed65..2be357b 100644
--- a/lib/std/syswrap-ss+openbsd.myr
+++ b/lib/std/syswrap-ss+openbsd.myr
@@ -15,7 +15,19 @@ pkg std =
const exit = {status; sys.exit(status)}
const bgetcwd = {buf
- -> (sys.__getcwd(buf) - 1 : errno)
+ var res = (sys.__getcwd(buf) : errno)
+
+ if res == 0
+ /* openbsd > 6.5 returns 0 on success */
+ -> (cstrlen(buf) : errno)
+ elif res > 0
+ /* openbsd <= 6.5 returns the length including nul byte */
+ -> res - 1
+ elif res == Enomem
+ -> Erange
+ else
+ -> res
+ ;;
}
const nanosleep = {nsecs