This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 4359bbb2f5d libs/libc/stdlib: Stop mktemp() at a stat() error other
than ENOENT.
4359bbb2f5d is described below
commit 4359bbb2f5d10327f35dd4b0909d688501619e2d
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 8 09:38:04 2026 +0100
libs/libc/stdlib: Stop mktemp() at a stat() error other than ENOENT.
mktemp() tries names until stat() fails with ENOENT. An error such as
ENAMETOOLONG, ENOTDIR or EACCES is the same for every name, so
mktemp() tried every name, up to UINT32_MAX of them, and did not
return. mkstemp(), mkostemps(), mkdtemp(), tempnam() and
memfd_create() call mktemp() and did not return either.
Return NULL at the first such error, with errno from stat().
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
libs/libc/stdlib/lib_mktemp.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/libs/libc/stdlib/lib_mktemp.c b/libs/libc/stdlib/lib_mktemp.c
index e742daa105e..3ca3d267e51 100644
--- a/libs/libc/stdlib/lib_mktemp.c
+++ b/libs/libc/stdlib/lib_mktemp.c
@@ -237,12 +237,19 @@ FAR char *mktemp(FAR char *path_template)
/* Attempt to stat the candidate file */
ret = stat(path_template, &buf);
- if (ret < 0 && get_errno() == ENOENT)
+ if (ret < 0)
{
- /* We have it... Clear the errno and return the template */
+ if (get_errno() == ENOENT)
+ {
+ /* We have it... Clear the errno and return the template */
- set_errno(0);
- return path_template;
+ set_errno(0);
+ return path_template;
+ }
+
+ /* Another name gives the same error: keep the errno and stop */
+
+ return NULL;
}
retries--;