Check for waitstatus orientation via cmake

Yeah we need the long way around because old glibc versions have weird WEXITSTATUS.
This commit is contained in:
Fabian Boehm 2022-07-24 16:39:57 +02:00
parent 122b6c1734
commit bcd84c6908
3 changed files with 14 additions and 1 deletions

View File

@ -268,6 +268,16 @@ IF (NOT LIBATOMIC_NOT_NEEDED)
set(ATOMIC_LIBRARY "atomic")
endif()
check_cxx_source_compiles("
#include <sys/wait.h>
int main() {
static_assert(WEXITSTATUS(0x007f) == 0x7f);
return 0;
}
"
HAVE_WAITSTATUS_SIGNAL_RET)
IF (APPLE)
# Check if mbrtowc implementation attempts to encode invalid UTF-8 sequences
# Known culprits: at least some versions of macOS (confirmed Snow Leopard and Yosemite)

View File

@ -103,6 +103,9 @@
/* Define to 1 if you have the `wcstod_l' function. */
#cmakedefine HAVE_WCSTOD_L 1
/* Define to 1 if the status that wait returns and WEXITSTATUS expects is signal and then ret instead of the other way around. */
#cmakedefine HAVE_WAITSTATUS_SIGNAL_RET 1
/* Define to 1 if the winsize struct and TIOCGWINSZ macro exist */
#cmakedefine HAVE_WINSIZE 1

View File

@ -73,7 +73,7 @@ class proc_status_t {
static constexpr int w_exitcode(int ret, int sig) {
#ifdef W_EXITCODE
return W_EXITCODE(ret, sig);
#elif WEXITSTATUS(0x007f) == 0x7f
#elif HAVE_WAITSTATUS_SIGNAL_RET
// It's encoded signal and then status
// The return status is in the lower byte.
return ((sig) << 8 | (ret));