summaryrefslogtreecommitdiff
path: root/lib/libc/stat
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
commitfc00c656c96528112d05cf0edf8631bd5eaea446 (patch)
treea6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/stat
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/stat')
-rw-r--r--lib/libc/stat/chmod.c7
-rw-r--r--lib/libc/stat/fchmod.c7
-rw-r--r--lib/libc/stat/fchmodat.c7
-rw-r--r--lib/libc/stat/fstat.c8
-rw-r--r--lib/libc/stat/fstatat.c46
-rw-r--r--lib/libc/stat/futimens.c7
-rw-r--r--lib/libc/stat/lstat.c7
-rw-r--r--lib/libc/stat/mkdir.c12
-rw-r--r--lib/libc/stat/mkdirat.c8
-rw-r--r--lib/libc/stat/mkfifo.c6
-rw-r--r--lib/libc/stat/mkfifoat.c6
-rw-r--r--lib/libc/stat/mknod.c8
-rw-r--r--lib/libc/stat/mknodat.c7
-rw-r--r--lib/libc/stat/stat.c7
-rw-r--r--lib/libc/stat/umask.c7
-rw-r--r--lib/libc/stat/utimensat.c8
16 files changed, 158 insertions, 0 deletions
diff --git a/lib/libc/stat/chmod.c b/lib/libc/stat/chmod.c
new file mode 100644
index 00000000..6b7283e2
--- /dev/null
+++ b/lib/libc/stat/chmod.c
@@ -0,0 +1,7 @@
+#include <sys/stat.h>
+#include <syscall.h>
+
+int chmod(const char *path, mode_t mode)
+{
+ return syscall(chmod, path, mode);
+}
diff --git a/lib/libc/stat/fchmod.c b/lib/libc/stat/fchmod.c
new file mode 100644
index 00000000..22593fd6
--- /dev/null
+++ b/lib/libc/stat/fchmod.c
@@ -0,0 +1,7 @@
+#include <sys/stat.h>
+#include <syscall.h>
+
+int fchmod(int fildes, mode_t mode)
+{
+ return syscall(fchmod, fildes, mode);
+}
diff --git a/lib/libc/stat/fchmodat.c b/lib/libc/stat/fchmodat.c
new file mode 100644
index 00000000..71a3c0c5
--- /dev/null
+++ b/lib/libc/stat/fchmodat.c
@@ -0,0 +1,7 @@
+#include <sys/stat.h>
+#include <syscall.h>
+
+int fchmodat(int fd, const char *path, mode_t mode, int flag)
+{
+ return syscall(fchmodat2, fd, path, mode, flag);
+}
diff --git a/lib/libc/stat/fstat.c b/lib/libc/stat/fstat.c
new file mode 100644
index 00000000..7a9fb4e4
--- /dev/null
+++ b/lib/libc/stat/fstat.c
@@ -0,0 +1,8 @@
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <syscall.h>
+
+int fstat(int fildes, struct stat *buf)
+{
+ return fstatat(fildes, "", buf, 0);
+}
diff --git a/lib/libc/stat/fstatat.c b/lib/libc/stat/fstatat.c
new file mode 100644
index 00000000..06b00163
--- /dev/null
+++ b/lib/libc/stat/fstatat.c
@@ -0,0 +1,46 @@
+#include <sys/stat.h>
+#include <syscall.h>
+
+#include <linux/stat.h>
+
+#define makedev(major, minor) \
+ ((((major) & 0xfffff000ULL) << 32) | \
+ (((major) & 0x00000fffULL) << 8) | \
+ (((minor) & 0xffffff00ULL) << 12) | (((minor) & 0x000000ffULL)))
+
+int fstatat(int fd, const char *restrict path, struct stat *restrict buf,
+ int flag)
+{
+ int ret;
+ struct statx stx = { 0 };
+
+ ret = syscall(statx, fd, path, flag, 0x7ff, &stx);
+
+ if (ret == 0) {
+ if (stx.stx_mask & STATX_BASIC_STATS) {
+ buf->st_dev =
+ makedev(stx.stx_dev_major, stx.stx_dev_minor);
+ buf->st_ino = stx.stx_ino;
+ buf->st_mode = stx.stx_mode;
+ buf->st_nlink = stx.stx_nlink;
+ buf->st_uid = stx.stx_uid;
+ buf->st_gid = stx.stx_gid;
+ buf->st_rdev =
+ makedev(stx.stx_rdev_major, stx.stx_rdev_minor);
+ buf->st_size = stx.stx_size;
+ buf->st_atim.tv_sec = stx.stx_atime.tv_sec;
+ buf->st_atim.tv_nsec = stx.stx_atime.tv_nsec;
+ buf->st_mtim.tv_sec = stx.stx_mtime.tv_sec;
+ buf->st_mtim.tv_nsec = stx.stx_mtime.tv_nsec;
+ buf->st_ctim.tv_sec = stx.stx_ctime.tv_sec;
+ buf->st_ctim.tv_nsec = stx.stx_ctime.tv_nsec;
+ buf->st_blksize = stx.stx_blksize;
+ buf->st_blocks = stx.stx_blocks;
+ } else {
+ ret = -1; // Indicate failure if STATX_BASIC_STATS is
+ // not set
+ }
+ }
+
+ return ret;
+}
diff --git a/lib/libc/stat/futimens.c b/lib/libc/stat/futimens.c
new file mode 100644
index 00000000..974d2eb7
--- /dev/null
+++ b/lib/libc/stat/futimens.c
@@ -0,0 +1,7 @@
+#include <stddef.h>
+#include <sys/stat.h>
+
+int futimens(int fd, const struct timespec times[2])
+{
+ return utimensat(fd, NULL, times, 0);
+}
diff --git a/lib/libc/stat/lstat.c b/lib/libc/stat/lstat.c
new file mode 100644
index 00000000..a188f78d
--- /dev/null
+++ b/lib/libc/stat/lstat.c
@@ -0,0 +1,7 @@
+#include <fcntl.h>
+#include <sys/stat.h>
+
+int lstat(const char *restrict path, struct stat *restrict buf)
+{
+ return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
+}
diff --git a/lib/libc/stat/mkdir.c b/lib/libc/stat/mkdir.c
new file mode 100644
index 00000000..1f97fb3f
--- /dev/null
+++ b/lib/libc/stat/mkdir.c
@@ -0,0 +1,12 @@
+#include <fcntl.h>
+#include <syscall.h>
+#include <sys/stat.h>
+
+int mkdir(const char *path, mode_t mode)
+{
+#ifdef __NR_mkdir
+ return syscall(mkdir, path, mode);
+#else
+ return syscall(mkdirat, AT_FDCWD, path, mode);
+#endif
+}
diff --git a/lib/libc/stat/mkdirat.c b/lib/libc/stat/mkdirat.c
new file mode 100644
index 00000000..d129008b
--- /dev/null
+++ b/lib/libc/stat/mkdirat.c
@@ -0,0 +1,8 @@
+#include <fcntl.h>
+#include <syscall.h>
+#include <sys/stat.h>
+
+int mkdirat(int fd, const char *path, mode_t mode)
+{
+ return syscall(mkdirat, fd, path, mode);
+}
diff --git a/lib/libc/stat/mkfifo.c b/lib/libc/stat/mkfifo.c
new file mode 100644
index 00000000..60efcf73
--- /dev/null
+++ b/lib/libc/stat/mkfifo.c
@@ -0,0 +1,6 @@
+#include <sys/stat.h>
+
+int mkfifo(const char *path, mode_t mode)
+{
+ return mknod(path, mode | S_IFIFO, 0);
+}
diff --git a/lib/libc/stat/mkfifoat.c b/lib/libc/stat/mkfifoat.c
new file mode 100644
index 00000000..d3a1f970
--- /dev/null
+++ b/lib/libc/stat/mkfifoat.c
@@ -0,0 +1,6 @@
+#include <sys/stat.h>
+
+int mkfifoat(int fd, const char *path, mode_t mode)
+{
+ return mknodat(fd, path, mode | S_IFIFO, 0);
+}
diff --git a/lib/libc/stat/mknod.c b/lib/libc/stat/mknod.c
new file mode 100644
index 00000000..1a4a5c6c
--- /dev/null
+++ b/lib/libc/stat/mknod.c
@@ -0,0 +1,8 @@
+#include <fcntl.h>
+#include <syscall.h>
+#include <sys/stat.h>
+
+int mknod(const char *path, mode_t mode, dev_t dev)
+{
+ return syscall(mknodat, AT_FDCWD, path, mode, dev);
+}
diff --git a/lib/libc/stat/mknodat.c b/lib/libc/stat/mknodat.c
new file mode 100644
index 00000000..9967248e
--- /dev/null
+++ b/lib/libc/stat/mknodat.c
@@ -0,0 +1,7 @@
+#include <syscall.h>
+#include <sys/stat.h>
+
+int mknodat(int fd, const char *path, mode_t mode, dev_t dev)
+{
+ return syscall(mknodat, fd, path, mode, dev);
+}
diff --git a/lib/libc/stat/stat.c b/lib/libc/stat/stat.c
new file mode 100644
index 00000000..95bdf73d
--- /dev/null
+++ b/lib/libc/stat/stat.c
@@ -0,0 +1,7 @@
+#include <fcntl.h>
+#include <sys/stat.h>
+
+int stat(const char *restrict path, struct stat *restrict buf)
+{
+ return fstatat(AT_FDCWD, path, buf, 0);
+}
diff --git a/lib/libc/stat/umask.c b/lib/libc/stat/umask.c
new file mode 100644
index 00000000..2724317a
--- /dev/null
+++ b/lib/libc/stat/umask.c
@@ -0,0 +1,7 @@
+#include <sys/stat.h>
+#include <syscall.h>
+
+mode_t umask(mode_t cmask)
+{
+ return syscall(umask, cmask);
+}
diff --git a/lib/libc/stat/utimensat.c b/lib/libc/stat/utimensat.c
new file mode 100644
index 00000000..d51611a3
--- /dev/null
+++ b/lib/libc/stat/utimensat.c
@@ -0,0 +1,8 @@
+#include <time.h>
+#include <syscall.h>
+
+int utimensat(int fd, const char *path, const struct timespec times[2],
+ int flag)
+{
+ return syscall(utimensat, fd, path, times, flag);
+}