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:
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.
@@ -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
