From 8929eb838bec8d3f5eb0d5a1c6b91a4f27d0baff Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 17 Jun 2023 18:42:52 +0200 Subject: libc: dumb stat() stubs to make dash's PATH search work --- src/user/lib/include/sys/stat.h | 21 +++------------------ src/user/lib/sysstat.c | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/user/lib/include/sys/stat.h b/src/user/lib/include/sys/stat.h index 26c8323..343db55 100644 --- a/src/user/lib/include/sys/stat.h +++ b/src/user/lib/include/sys/stat.h @@ -47,24 +47,9 @@ struct stat { #define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK) #define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK) -static inline int fstat(int fd, struct stat *sb) { - (void)fd; (void)sb; - errno = ENOSYS; - return -1; -} - -static inline int stat(const char *restrict path, struct stat *restrict sb) { - (void)path; (void)sb; - errno = ENOSYS; - return -1; -} - -static inline int lstat(const char *restrict path, struct stat *restrict sb) { - (void)path; (void)sb; - errno = ENOSYS; - return -1; -} - +int fstat(int fd, struct stat *sb); +int stat(const char *restrict path, struct stat *restrict sb); +int lstat(const char *restrict path, struct stat *restrict sb); int mkdir(const char *path, mode_t mode); static inline mode_t umask(mode_t mask) { diff --git a/src/user/lib/sysstat.c b/src/user/lib/sysstat.c index df192c5..97bb50b 100644 --- a/src/user/lib/sysstat.c +++ b/src/user/lib/sysstat.c @@ -1,7 +1,33 @@ +#include #include #include #include #include +#include + +int fstat(int fd, struct stat *sb) { + (void)fd; + memset(sb, 0, sizeof sb); + // TODO save info if it was a dir + sb->st_mode = 0777 | S_IFREG; + return 0; +} + +int stat(const char *restrict path, struct stat *restrict sb) { + int fd, ret; + fd = camellia_open(path, OPEN_READ); + if (fd < 0) { + return -1; + } + ret = fstat(fd, sb); + close(fd); + return ret; +} + +int lstat(const char *restrict path, struct stat *restrict sb) { + // TODO assumes no symlink support + return stat(path, sb); +} int mkdir(const char *path, mode_t mode) { // TODO error when directory already exits -- cgit v1.2.3