writing to closed stdout (II): exit status
Paul Backus
snarwin at gmail.com
Sun Dec 15 17:16:11 UTC 2024
On Sunday, 15 December 2024 at 14:32:13 UTC, kdevel wrote:
> Surprisingly when the return value is anything but 0 the exit
> code of the program becomes `rv & 255`.
The POSIX standard specifies that the status code you get from
`wait` and `waitpid` is truncated to 8 bits. [1] Probably this is
because it needs to be packed into a single `int` variable
alongside other metadata (`WIFEXITED`, `WIFSIGNALED`, and so on),
and the C standard only guarantees that `int` will have at least
16 bits. [2]
It's possible to get the full exit status from `waitid` [3], so
you can't necessarily *assume* that the upper bits are ignored,
but relying on them probably isn't a great idea either.
[1]
https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html
[2] http://port70.net/~nsz/c/c11/n1570.html#5.2.4.2.1
[3]
https://pubs.opengroup.org/onlinepubs/9699919799/functions/waitid.html
More information about the Digitalmars-d
mailing list