summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/user/lib/include/sys/stat.h21
-rw-r--r--src/user/lib/sysstat.c26
2 files changed, 29 insertions, 18 deletions
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 <camellia.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <unistd.h>
+
+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