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
commit 220ae585cee87e7ee4aee1825decfb01af119674 Author: Marco Casaroli <[email protected]> AuthorDate: Sat Oct 17 19:58:31 2026 +0200 libs/libc/misc: Support AT_EMPTY_PATH in fstatat(). fstatat() ignored the AT_EMPTY_PATH flag. An empty path then worked only by accident: lib_getfullpath() joined the path of dirfd (or the current directory) with the empty string. fstatat() now handles AT_EMPTY_PATH with an empty path. It calls fstat() on dirfd, or uses the current directory when dirfd is AT_FDCWD. This is the Linux behavior. It also works for a dirfd that is not a directory. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- libs/libc/misc/lib_fstatat.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libs/libc/misc/lib_fstatat.c b/libs/libc/misc/lib_fstatat.c index 4a1ded9773b..e91d3768533 100644 --- a/libs/libc/misc/lib_fstatat.c +++ b/libs/libc/misc/lib_fstatat.c @@ -52,11 +52,15 @@ * * If pathname is absolute, then dirfd is ignored. * + * If pathname is an empty string and flags contains AT_EMPTY_PATH, then + * the call operates on the file referred to by dirfd (like fstat()). If + * dirfd is AT_FDCWD, the call operates on the current working directory. + * * Input Parameters: * dirfd - The file descriptor of directory. * path - A pointer to the path. * buf - The buf to get file status. - * flags - Ignored. + * flags - AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH are supported. * * Returned Value: * Return zero on success, or -1 if an error occurred (in which case, @@ -70,6 +74,16 @@ int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf, FAR char *fullpath; int ret; + if (path != NULL && path[0] == '\0' && (flags & AT_EMPTY_PATH) != 0) + { + if (dirfd != AT_FDCWD) + { + return fstat(dirfd, buf); + } + + path = "."; + } + fullpath = lib_get_pathbuffer(); if (fullpath == NULL) {
