Fix exit code on BSD/Mac
Created by: dvkt
Continuing the conversation from 3f5325a6...
Currently on master,
the exit code for EXECUTE - AND STORE EXIT CODE IN
is always 0. I did some digging and it looks like BSD has a different WEXITSTATUS() macro than Linux:
OpenBSD's implementation of WEXITSTATUS uses the address-of operator (unary &) on its argument, effectively requiring that its argument have storage. You are calling it with the return value of a function, which doesn't have storage, so the compiler complains. - https://stackoverflow.com/a/13674801
Here's BSD/Mac's:
Which uses the _W_INT
macro:
And glibc's, which doesn't:
https://github.com/bminor/glibc/blob/7628a1b05adb1e4c6857b87c6f8b71a1d0b1d72c/posix/sys/wait.h#L54
https://github.com/bminor/glibc/blob/7628a1b05adb1e4c6857b87c6f8b71a1d0b1d72c/bits/waitstatus.h#L28
I tried a few things but I suspect the most portable would just be to overwrite _W_INT
if it exists to do what we want. Sounds like only really old code expects wait() to return a union on BSDs, anyway.
I also added the explicit (int)
cast which my Linux machines needed, for some reason.