Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions expected/wasm32-wasip1-threads/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define ARG_MAX 131072
#define ARMAG "!<arch>\n"
#define AT_EACCESS (0x0)
#define AT_EMPTY_PATH (0x8)
#define AT_FDCWD (-2)
#define AT_REMOVEDIR (0x4)
#define AT_SYMLINK_FOLLOW (0x2)
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define ARG_MAX 131072
#define ARMAG "!<arch>\n"
#define AT_EACCESS (0x0)
#define AT_EMPTY_PATH (0x8)
#define AT_FDCWD (-2)
#define AT_REMOVEDIR (0x4)
#define AT_SYMLINK_FOLLOW (0x2)
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip2/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define ARG_MAX 131072
#define ARMAG "!<arch>\n"
#define AT_EACCESS (0x0)
#define AT_EMPTY_PATH (0x8)
#define AT_FDCWD (-2)
#define AT_REMOVEDIR (0x4)
#define AT_SYMLINK_FOLLOW (0x2)
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip3-coop/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define ARG_MAX 131072
#define ARMAG "!<arch>\n"
#define AT_EACCESS (0x0)
#define AT_EMPTY_PATH (0x8)
#define AT_FDCWD (-2)
#define AT_REMOVEDIR (0x4)
#define AT_SYMLINK_FOLLOW (0x2)
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip3/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define ARG_MAX 131072
#define ARMAG "!<arch>\n"
#define AT_EACCESS (0x0)
#define AT_EMPTY_PATH (0x8)
#define AT_FDCWD (-2)
#define AT_REMOVEDIR (0x4)
#define AT_SYMLINK_FOLLOW (0x2)
Expand Down
9 changes: 9 additions & 0 deletions libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *restrict buf,
int flag) {
if (path[0] == '\0') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also check flag for AT_EMPTY_PATH and skip this check in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you it should be taken into account. I was looking into POSIX.1-2017 documentation, which does not reference the flag, so I will update the description pointing to POSIX.1-2024 docs.

// With AT_EMPTY_PATH an empty path refers to fd itself; otherwise the
// WASI path-relative stat calls cannot resolve it, so reject as ENOENT.
if (flag & AT_EMPTY_PATH)
return fstat(fd, buf);
errno = ENOENT;
return -1;
}

#if defined(__wasip1__)
__wasi_lookupflags_t lookup_flags = 0;
if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
Expand Down
1 change: 1 addition & 0 deletions libc-bottom-half/headers/public/__header_fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#define AT_SYMLINK_NOFOLLOW (0x1)
#define AT_SYMLINK_FOLLOW (0x2)
#define AT_REMOVEDIR (0x4)
#define AT_EMPTY_PATH (0x8)

#define AT_FDCWD (-2)

Expand Down
15 changes: 15 additions & 0 deletions libc-bottom-half/sources/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ ssize_t readlink(const char *restrict path, char *restrict buf,
}

int stat(const char *restrict path, struct stat *restrict buf) {
if (path[0] == '\0') {
errno = ENOENT;
return -1;
}

char *relative_path;
int dirfd = find_relpath(path, &relative_path);

Expand All @@ -106,6 +111,11 @@ int stat(const char *restrict path, struct stat *restrict buf) {
}

int lstat(const char *restrict path, struct stat *restrict buf) {
if (path[0] == '\0') {
errno = ENOENT;
return -1;
}

char *relative_path;
int dirfd = find_relpath(path, &relative_path);

Expand Down Expand Up @@ -387,6 +397,11 @@ int __wasilibc_utimens(const char *path, const struct timespec times[2],
// Like `stat`, but with `fstatat`'s flags argument.
int __wasilibc_stat(const char *__restrict path, struct stat *__restrict st,
int flags) {
if (path[0] == '\0') {
errno = ENOENT;
return -1;
}

char *relative_path;
int dirfd = find_relpath(path, &relative_path);

Expand Down
15 changes: 15 additions & 0 deletions test/src/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "test.h"
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -27,6 +28,20 @@ int main(void) {
FILE *f;
time_t t;

TEST(stat("", &st) == -1 && errno == ENOENT, "errno = %s\n", strerror(errno));
TEST(lstat("", &st) == -1 && errno == ENOENT, "errno = %s\n",
strerror(errno));
int dirfd = open(".", O_RDONLY);
if (TEST(dirfd >= 0, "errno = %s\n", strerror(errno))) {
TEST(fstatat(dirfd, "", &st, 0) == -1 && errno == ENOENT, "errno = %s\n",
strerror(errno));
if (TEST(fstatat(dirfd, "", &st, AT_EMPTY_PATH) == 0, "errno = %s\n",
strerror(errno))) {
TEST(S_ISDIR(st.st_mode), "\n");
}
close(dirfd);
}

if (TEST(stat(".", &st) == 0, "errno = %s\n", strerror(errno))) {
TEST(S_ISDIR(st.st_mode), "\n");
TEST(st.st_nlink > 0, "%ju\n", (uintmax_t)st.st_nlink);
Expand Down
Loading