From b8b57ba75020c224ae6c5f068cd3514c9a4d7d91 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 15 Feb 2025 11:17:19 +0100 Subject: Reverse conditional compilation of non-POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As https://www.openbsd.org/faq/ports/guide.html#PortsGeneric states, it is inappropriate to base feature inclusion on a growing list (60b66fc, 9160d12) of excluded platforms. Thus this commit attempts to switch the assumption from Linux to a modern POSIX as the default target. Firstly, merely checking for __unix__ should be functionally equivalent of having a long lists of practically "all" operating systems. Apart from Windows, the primary non-standard code covers these termios related constants: I_IUCLC, O_OLCUC, O_OFILL, O_OFDEL, O_NLDLY, O_CRDLY and L_XCASE. A few of them are documented as LEGACY as they were removed from POSIX https://pubs.opengroup.org/onlinepubs/007904875/basedefs/termios.h.html over two decades ago. The other constants are part of the X/Open System Interfaces, which supposedly should be available when _XOPEN_UNIX is set to another value than -1. However on Linux they exist, yet the variable indicating their presence is undefined. In summary; It is hard to find any feature specific preprocessor variables indicating availability, but it is quite safe to limit their inclusion to Linux until patches arrive for other platforms. Executing `cpp -dM #if defined(__linux__) #include // getrandom() - #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) + #elif defined(__APPLE__) || defined(__unix__) #include // arc4random_buf() #endif #endif @@ -80,7 +80,7 @@ static int lua_get_random_bytes(lua_State* L) { total_read += n; } -#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#elif defined(__APPLE__) || defined(__unix__) // Use arc4random_buf() on BSD/macOS arc4random_buf(buffer, num_bytes); diff --git a/src/term.c b/src/term.c index 2375080..7f09c7f 100644 --- a/src/term.c +++ b/src/term.c @@ -166,8 +166,8 @@ static const struct ls_RegConst nix_console_i_flags[] = { {"I_INLCR", CHECK_NIX_FLAG_OR_ZERO(INLCR)}, {"I_IGNCR", CHECK_NIX_FLAG_OR_ZERO(IGNCR)}, {"I_ICRNL", CHECK_NIX_FLAG_OR_ZERO(ICRNL)}, -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) - {"I_IUCLC", CHECK_NIX_FLAG_OR_ZERO(IUCLC)}, // Might not be available on all systems +#ifdef __linux__ + {"I_IUCLC", CHECK_NIX_FLAG_OR_ZERO(IUCLC)}, // Might also exist on AIX #else {"I_IUCLC", 0}, #endif @@ -181,8 +181,8 @@ static const struct ls_RegConst nix_console_i_flags[] = { static const struct ls_RegConst nix_console_o_flags[] = { // Output flags (c_oflag) {"O_OPOST", CHECK_NIX_FLAG_OR_ZERO(OPOST)}, -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) - {"O_OLCUC", CHECK_NIX_FLAG_OR_ZERO(OLCUC)}, // Might not be available on all systems +#ifdef __linux__ + {"O_OLCUC", CHECK_NIX_FLAG_OR_ZERO(OLCUC)}, // Might also exist on AIX #else {"O_OLCUC", 0}, #endif @@ -190,11 +190,11 @@ static const struct ls_RegConst nix_console_o_flags[] = { {"O_OCRNL", CHECK_NIX_FLAG_OR_ZERO(OCRNL)}, {"O_ONOCR", CHECK_NIX_FLAG_OR_ZERO(ONOCR)}, {"O_ONLRET", CHECK_NIX_FLAG_OR_ZERO(ONLRET)}, -#if !defined(__FreeBSD__) && !defined(__NetBSD__) - {"O_OFILL", CHECK_NIX_FLAG_OR_ZERO(OFILL)}, - {"O_OFDEL", CHECK_NIX_FLAG_OR_ZERO(OFDEL)}, - {"O_NLDLY", CHECK_NIX_FLAG_OR_ZERO(NLDLY)}, - {"O_CRDLY", CHECK_NIX_FLAG_OR_ZERO(CRDLY)}, +#if defined(__APPLE__) || defined(__linux__) + {"O_OFILL", CHECK_NIX_FLAG_OR_ZERO(OFILL)}, // Might also exist on AIX + {"O_OFDEL", CHECK_NIX_FLAG_OR_ZERO(OFDEL)}, // Might also exist on AIX + {"O_NLDLY", CHECK_NIX_FLAG_OR_ZERO(NLDLY)}, // Might also exist on AIX + {"O_CRDLY", CHECK_NIX_FLAG_OR_ZERO(CRDLY)}, // Might also exist on AIX #else {"O_OFILL", 0}, {"O_OFDEL", 0}, @@ -206,10 +206,10 @@ static const struct ls_RegConst nix_console_o_flags[] = { #else {"O_TABDLY", 0}, #endif -#if !defined(__FreeBSD__) && !defined(__NetBSD__) - {"O_BSDLY", CHECK_NIX_FLAG_OR_ZERO(BSDLY)}, - {"O_VTDLY", CHECK_NIX_FLAG_OR_ZERO(VTDLY)}, - {"O_FFDLY", CHECK_NIX_FLAG_OR_ZERO(FFDLY)}, +#if defined(__APPLE__) || defined(__linux__) + {"O_BSDLY", CHECK_NIX_FLAG_OR_ZERO(BSDLY)}, // Might also exist on AIX + {"O_VTDLY", CHECK_NIX_FLAG_OR_ZERO(VTDLY)}, // Might also exist on AIX + {"O_FFDLY", CHECK_NIX_FLAG_OR_ZERO(FFDLY)}, // Might also exist on AIX #else {"O_BSDLY", 0}, {"O_VTDLY", 0}, @@ -222,8 +222,8 @@ static const struct ls_RegConst nix_console_l_flags[] = { // Local flags (c_lflag) {"L_ISIG", CHECK_NIX_FLAG_OR_ZERO(ISIG)}, {"L_ICANON", CHECK_NIX_FLAG_OR_ZERO(ICANON)}, -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) - {"L_XCASE", CHECK_NIX_FLAG_OR_ZERO(XCASE)}, // Might not be available on all systems +#ifdef __linux__ + {"L_XCASE", CHECK_NIX_FLAG_OR_ZERO(XCASE)}, // Might also exist on AIX #else {"L_XCASE", 0}, #endif -- cgit v1.2.3-55-g6feb