aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2025-02-15 11:17:19 +0100
committerThijs Schreijer <thijs@thijsschreijer.nl>2025-02-25 12:47:59 +0100
commitb8b57ba75020c224ae6c5f068cd3514c9a4d7d91 (patch)
tree9cdeb178e0b2de08ea3b23303f7a7d13189a35c3
parentafd939e6afa79932e96950539ce108ab2c644217 (diff)
downloadluasystem-b8b57ba75020c224ae6c5f068cd3514c9a4d7d91.tar.gz
luasystem-b8b57ba75020c224ae6c5f068cd3514c9a4d7d91.tar.bz2
luasystem-b8b57ba75020c224ae6c5f068cd3514c9a4d7d91.zip
Reverse conditional compilation of non-POSIX
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 </dev/null | grep -i linux` on contemporary glibc and musl based distributions tend to give a few constants, where __linux__ likely is the one most suitable. Based on the previous state of the code, the following constants are expected to be available also on Apple: O_BSDLY, O_VTDLY and O_FFDLY. They do not appear be documented in termios(4) on macOS 13, but they actually exist in /Library/Developer/…/sys/termios.h. Lastly, O_TABDLY is kept excluded exclusively for NetBSD as that is the only currently supported platform lacking it.
-rw-r--r--src/random.c4
-rw-r--r--src/term.c30
2 files changed, 17 insertions, 17 deletions
diff --git a/src/random.c b/src/random.c
index 70bf13b..7bffe30 100644
--- a/src/random.c
+++ b/src/random.c
@@ -18,7 +18,7 @@
18 #include <string.h> 18 #include <string.h>
19 #if defined(__linux__) 19 #if defined(__linux__)
20 #include <sys/random.h> // getrandom() 20 #include <sys/random.h> // getrandom()
21 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) 21 #elif defined(__APPLE__) || defined(__unix__)
22 #include <stdlib.h> // arc4random_buf() 22 #include <stdlib.h> // arc4random_buf()
23 #endif 23 #endif
24#endif 24#endif
@@ -80,7 +80,7 @@ static int lua_get_random_bytes(lua_State* L) {
80 total_read += n; 80 total_read += n;
81 } 81 }
82 82
83#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) 83#elif defined(__APPLE__) || defined(__unix__)
84 // Use arc4random_buf() on BSD/macOS 84 // Use arc4random_buf() on BSD/macOS
85 arc4random_buf(buffer, num_bytes); 85 arc4random_buf(buffer, num_bytes);
86 86
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[] = {
166 {"I_INLCR", CHECK_NIX_FLAG_OR_ZERO(INLCR)}, 166 {"I_INLCR", CHECK_NIX_FLAG_OR_ZERO(INLCR)},
167 {"I_IGNCR", CHECK_NIX_FLAG_OR_ZERO(IGNCR)}, 167 {"I_IGNCR", CHECK_NIX_FLAG_OR_ZERO(IGNCR)},
168 {"I_ICRNL", CHECK_NIX_FLAG_OR_ZERO(ICRNL)}, 168 {"I_ICRNL", CHECK_NIX_FLAG_OR_ZERO(ICRNL)},
169#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) 169#ifdef __linux__
170 {"I_IUCLC", CHECK_NIX_FLAG_OR_ZERO(IUCLC)}, // Might not be available on all systems 170 {"I_IUCLC", CHECK_NIX_FLAG_OR_ZERO(IUCLC)}, // Might also exist on AIX
171#else 171#else
172 {"I_IUCLC", 0}, 172 {"I_IUCLC", 0},
173#endif 173#endif
@@ -181,8 +181,8 @@ static const struct ls_RegConst nix_console_i_flags[] = {
181static const struct ls_RegConst nix_console_o_flags[] = { 181static const struct ls_RegConst nix_console_o_flags[] = {
182 // Output flags (c_oflag) 182 // Output flags (c_oflag)
183 {"O_OPOST", CHECK_NIX_FLAG_OR_ZERO(OPOST)}, 183 {"O_OPOST", CHECK_NIX_FLAG_OR_ZERO(OPOST)},
184#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) 184#ifdef __linux__
185 {"O_OLCUC", CHECK_NIX_FLAG_OR_ZERO(OLCUC)}, // Might not be available on all systems 185 {"O_OLCUC", CHECK_NIX_FLAG_OR_ZERO(OLCUC)}, // Might also exist on AIX
186#else 186#else
187 {"O_OLCUC", 0}, 187 {"O_OLCUC", 0},
188#endif 188#endif
@@ -190,11 +190,11 @@ static const struct ls_RegConst nix_console_o_flags[] = {
190 {"O_OCRNL", CHECK_NIX_FLAG_OR_ZERO(OCRNL)}, 190 {"O_OCRNL", CHECK_NIX_FLAG_OR_ZERO(OCRNL)},
191 {"O_ONOCR", CHECK_NIX_FLAG_OR_ZERO(ONOCR)}, 191 {"O_ONOCR", CHECK_NIX_FLAG_OR_ZERO(ONOCR)},
192 {"O_ONLRET", CHECK_NIX_FLAG_OR_ZERO(ONLRET)}, 192 {"O_ONLRET", CHECK_NIX_FLAG_OR_ZERO(ONLRET)},
193#if !defined(__FreeBSD__) && !defined(__NetBSD__) 193#if defined(__APPLE__) || defined(__linux__)
194 {"O_OFILL", CHECK_NIX_FLAG_OR_ZERO(OFILL)}, 194 {"O_OFILL", CHECK_NIX_FLAG_OR_ZERO(OFILL)}, // Might also exist on AIX
195 {"O_OFDEL", CHECK_NIX_FLAG_OR_ZERO(OFDEL)}, 195 {"O_OFDEL", CHECK_NIX_FLAG_OR_ZERO(OFDEL)}, // Might also exist on AIX
196 {"O_NLDLY", CHECK_NIX_FLAG_OR_ZERO(NLDLY)}, 196 {"O_NLDLY", CHECK_NIX_FLAG_OR_ZERO(NLDLY)}, // Might also exist on AIX
197 {"O_CRDLY", CHECK_NIX_FLAG_OR_ZERO(CRDLY)}, 197 {"O_CRDLY", CHECK_NIX_FLAG_OR_ZERO(CRDLY)}, // Might also exist on AIX
198#else 198#else
199 {"O_OFILL", 0}, 199 {"O_OFILL", 0},
200 {"O_OFDEL", 0}, 200 {"O_OFDEL", 0},
@@ -206,10 +206,10 @@ static const struct ls_RegConst nix_console_o_flags[] = {
206#else 206#else
207 {"O_TABDLY", 0}, 207 {"O_TABDLY", 0},
208#endif 208#endif
209#if !defined(__FreeBSD__) && !defined(__NetBSD__) 209#if defined(__APPLE__) || defined(__linux__)
210 {"O_BSDLY", CHECK_NIX_FLAG_OR_ZERO(BSDLY)}, 210 {"O_BSDLY", CHECK_NIX_FLAG_OR_ZERO(BSDLY)}, // Might also exist on AIX
211 {"O_VTDLY", CHECK_NIX_FLAG_OR_ZERO(VTDLY)}, 211 {"O_VTDLY", CHECK_NIX_FLAG_OR_ZERO(VTDLY)}, // Might also exist on AIX
212 {"O_FFDLY", CHECK_NIX_FLAG_OR_ZERO(FFDLY)}, 212 {"O_FFDLY", CHECK_NIX_FLAG_OR_ZERO(FFDLY)}, // Might also exist on AIX
213#else 213#else
214 {"O_BSDLY", 0}, 214 {"O_BSDLY", 0},
215 {"O_VTDLY", 0}, 215 {"O_VTDLY", 0},
@@ -222,8 +222,8 @@ static const struct ls_RegConst nix_console_l_flags[] = {
222 // Local flags (c_lflag) 222 // Local flags (c_lflag)
223 {"L_ISIG", CHECK_NIX_FLAG_OR_ZERO(ISIG)}, 223 {"L_ISIG", CHECK_NIX_FLAG_OR_ZERO(ISIG)},
224 {"L_ICANON", CHECK_NIX_FLAG_OR_ZERO(ICANON)}, 224 {"L_ICANON", CHECK_NIX_FLAG_OR_ZERO(ICANON)},
225#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) 225#ifdef __linux__
226 {"L_XCASE", CHECK_NIX_FLAG_OR_ZERO(XCASE)}, // Might not be available on all systems 226 {"L_XCASE", CHECK_NIX_FLAG_OR_ZERO(XCASE)}, // Might also exist on AIX
227#else 227#else
228 {"L_XCASE", 0}, 228 {"L_XCASE", 0},
229#endif 229#endif