casaroli opened a new pull request, #21046: URL: https://github.com/apache/nuttx/pull/21046
## Summary `<stdlib.h>` maps `mkostemp64()`, `mkstemps64()` and `mkostemps64()` to `mkostemp()`, `mkstemps()` and `mkostemps()`, but libc does not have these three functions. `mkostemp()` is in POSIX.1-2024; `mkstemps()` and `mkostemps()` are in the other C libraries. A program that uses them does not compile or link. This PR adds them to `libs/libc/stdlib/lib_mkstemp.c`: - `mkostemps(template, suffixlen, flags)` replaces the X's before a suffix of `suffixlen` characters and creates the file with `O_RDWR | O_CREAT | O_EXCL` and the extra `open()` flags (for example `O_CLOEXEC` or `O_APPEND`). `mktemp()` makes the X's, with the suffix cut off while it runs. If the file exists (another process made it in the meantime), it tries the next name. - `mkostemp()`, `mkstemps()` and `mkstemp()` call it. So `mkstemp()` now also tries again when the file exists, instead of failing with `EEXIST`. The prototypes are in `<stdlib.h>` and the functions in `libc.csv`. ## Impact New functions in libc. `mkstemp()` behaves as before, except that it tries another name when the file exists. All build modes and architectures. Documentation (separate commit): the file system reference lists the three functions next to `mkstemp()`, and gives `mktemp()` its real return type. `Documentation/standards/posix.rst` already lists `mkostemp()` as supported; this PR makes that true. ## Testing Test program `mkostest.c`: `mkstemps()` with a `.txt` suffix (two calls give two different files, the suffix stays, the X's are replaced, the file can be written), `mkostemp()` with `O_CLOEXEC`, `mkostemps()` with `O_APPEND`, `mkstemp()`, and `EINVAL` for a suffix longer than the template. | | master | this PR | |---|---|---| | `mkostest.c` on `qemu-armv8a:knsh` (QEMU with HVF, files on a 9p share) | does not compile: implicit declaration of `mkstemps`, `mkostemp`, `mkostemps` | PASS | | ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | status 0 | status 0 | Build, each OK: `qemu-armv8a:nsh` (flat, arm64), `qemu-armv8a:knsh` (kernel, arm64), `rv-virt:knsh64` (kernel, rv64), `rv-virt:pnsh64` (protected, rv64), `lm3s6965-ek:qemu-protected` (protected, armv7-m). No new warnings. `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]
