ref: ef03dd4e5de858a096e880e19eb7ed3acf857f5c
parent: a4eb9c0aca8ae4adb6c50133ba26bbd250ae934d
author: Carlin Bingham <[email protected]>
date: Mon Jul 22 23:12:29 EDT 2019
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.
--- a/lib/std/syswrap-ss+openbsd.myr
+++ b/lib/std/syswrap-ss+openbsd.myr
@@ -15,7 +15,19 @@
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