diff options
author | cos <cos> | 2025-02-15 11:17:19 +0100 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2025-02-25 12:47:59 +0100 |
commit | b8b57ba75020c224ae6c5f068cd3514c9a4d7d91 (patch) | |
tree | 9cdeb178e0b2de08ea3b23303f7a7d13189a35c3 /src/random.c | |
parent | afd939e6afa79932e96950539ce108ab2c644217 (diff) | |
download | luasystem-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.
Diffstat (limited to 'src/random.c')
-rw-r--r-- | src/random.c | 4 |
1 files changed, 2 insertions, 2 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 | ||