Inside my atexit() registered function I would like to get the exit status (either the argument to exit(3) or what main() returned with).
Is there any portable way of doing this? Is there any GNU libc specific way of doing it such as a global holding that value I can reference?
Here’s a hack:
Won’t work for
return, but, hey, it’s portable!On a more maintainer-friendly note, you may want to consider writing some form of wrapper to do something similar to this for you. Hacking around how GCC implements
exit()sounds like a maintenance nightmare. Better to write a few helper functions that exit for you, and maybe even mask them with macros if you’re into that kind of thing. With a macro you might even be able to replacereturncalls, if you always callreturnwith parenthesis. Though this sounds like even more of a maintenance nightmare.