casaroli opened a new pull request, #21058: URL: https://github.com/apache/nuttx/pull/21058
## Summary Six small additions to public headers. The BSDs, glibc and musl have these names, and programs written for them do not compile against the NuttX headers without them. There is one commit for each header: - `<sys/select.h>`: `fd_mask` (the element type of `fd_set`) and `NFDBITS` (its number of bits). Some configure scripts look for `fd_mask` to find `fd_set` in `<sys/select.h>` (Tcl's took `int` for the `select()` masks, which then did not compile). `fd_set` does not change: its element type was already `uint32_t`. - `<sys/param.h>`: `MAXNAMLEN` (the BSD name of `NAME_MAX`, beside `MAXHOSTNAMELEN` and `MAXPATHLEN`) and `NBBY` (the number of bits in a byte). - `<netinet/in.h>`: `IN6_ARE_ADDR_EQUAL()`, beside the `IN6_IS_ADDR_*()` macros. - `<dirent.h>`: `IFTODT()` and `DTTOIF()`, which convert between the file type of `st_mode` and `d_type`. In NuttX each `S_IFxxx` is `DT_xxx << 12` (also for the NuttX types such as `S_IFMQ`), as in glibc and the BSDs. - `<string.h>`: also declares `index()` and `rindex()`, as glibc and the BSDs do, next to `strcasecmp()` and `strncasecmp()`, which are there for the same reason. Older programs call them with only `<string.h>` and get an implicit declaration, which newer compilers reject. - `<stdlib.h>`: includes `<alloca.h>`, as glibc's does (and as the NuttX `<string.h>` already does), so `alloca()` works with only `<stdlib.h>`. ## Impact New macros and a typedef, two more prototypes in `<string.h>` and one more include in `<stdlib.h>`. A program that defines one of these names for itself sees a conflict, as with the other C libraries. NuttX and nuttx-apps do not define them (checked with `git grep` in both; only the host tools `tools/mkdeps.c` and `tools/zds/zdsar.c` test `MAXNAMLEN`, with the host headers). All build modes and architectures. Documentation: no change. ## Testing Seven test programs, one for each name, built with the export of qemu-armv8a:knsh and run on qemu-armv8a:knsh (QEMU with HVF). `stringstrings.c` and `stdliballoca.c` include only `<string.h>` or `<stdlib.h>` and are compiled with `-Werror=implicit-function-declaration`. | Test | master | this PR | |---|---|---| | `fdmask.c`: `NFDBITS == 8 * sizeof(fd_mask)`, `fd_set` is a whole number of `fd_mask`; `select()` on stdout | does not compile (unknown type name `fd_mask`) | PASS | | `maxnamlen.c`: `MAXNAMLEN == NAME_MAX` | does not compile (`'MAXNAMLEN' undeclared`) | PASS | | `nbby.c`: `NBBY == CHAR_BIT`, usable in an array size | does not compile (`'NBBY' undeclared`) | PASS | | `in6eq.c`: `IN6_ARE_ADDR_EQUAL()` of equal and different addresses | does not compile (implicit declaration) | PASS | | `iftodt.c`: `IFTODT()` and `DTTOIF()` for the seven file types; `IFTODT(st_mode)` equals `d_type` for each entry of `/` and `/dev` | does not compile (implicit declaration) | PASS | | `stringstrings.c`: `index()` and `rindex()` with only `<string.h>` | does not compile (implicit declaration of `index`, `rindex`) | PASS | | `stdliballoca.c`: `alloca()` with only `<stdlib.h>` | does not compile (implicit declaration of `alloca`) | PASS | Header sweep with the same export: each of the public headers (not `nuttx/`, `arch/`, C++) compiled alone with `-Werror` at `-O0`, `-O2` and `-Os`. The results are the same on master and with this PR, both without and with `#define NUTTX_NO_EXTENSIONS 1`: 216 of 233 headers compile, and the same 17 fail at all levels for other reasons (for example `sys/syscall_lookup.h` and the `metal/system/nuttx/` headers, which are not for direct inclusion). ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh. Build, each OK: qemu-armv8a:nsh (flat, arm64), qemu-armv8a:knsh (kernel, arm64), rv-virt:nsh64 (flat, rv64), rv-virt:pnsh64 (protected, rv64), rv-virt:knsh64 (kernel, rv64), lm3s6965-ek:qemu-protected (protected, armv7-m), and rv-virt:nsh64 with CMake. `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
