Commit: 635329c72144287a2247ebadf56ca93967a8f595
Parent: 5dd81eaa0fb4fd1249df2bf9479664b8eff28c3e
Author: Randy Palamar
Date: Fri, 29 Nov 2024 19:32:14 -0700
drop sys/inotify.h include
Diffstat:
3 files changed, 40 insertions(+), 23 deletions(-)
diff --git a/platform_linux_amd64.c b/platform_linux_amd64.c
@@ -8,17 +8,20 @@
#endif
#endif
-#define SYS_read 0
-#define SYS_write 1
-#define SYS_open 2
-#define SYS_close 3
-#define SYS_stat 4
-#define SYS_mmap 9
-#define SYS_clone 56
-#define SYS_exit 60
-#define SYS_prctl 157
-#define SYS_futex 202
-#define SYS_getdents64 217
+#define SYS_read 0
+#define SYS_write 1
+#define SYS_open 2
+#define SYS_close 3
+#define SYS_stat 4
+#define SYS_mmap 9
+#define SYS_clone 56
+#define SYS_exit 60
+#define SYS_prctl 157
+#define SYS_futex 202
+#define SYS_getdents64 217
+#define SYS_inotify_add_watch 254
+#define SYS_inotify_rm_watch 255
+#define SYS_inotify_init1 294
#define PAGE_SIZE 4096
diff --git a/platform_linux_common.c b/platform_linux_common.c
@@ -9,6 +9,15 @@
#define MAP_FIXED 0x10
#define MAP_ANON 0x20
+#define O_CLOEXEC 0x80000
+#define O_NONBLOCK 0x00800
+
+#define IN_CLOSE_WRITE 0x00000008
+#define IN_CLOSE_NOWRITE 0x00000010
+#define IN_MODIFY 0x00000002
+
+#define LINUX_INOTIFY_MASK (IN_CLOSE_WRITE|IN_CLOSE_NOWRITE|IN_MODIFY)
+
#ifndef VERSION
#define VERSION "unknown"
#endif
@@ -59,10 +68,6 @@ typedef struct {
} PlatformCtx;
static PlatformCtx linux_ctx;
-#include <sys/inotify.h>
-
-#define LINUX_INOTIFY_MASK (IN_CLOSE|IN_MODIFY)
-
static void
os_write_err_msg(s8 msg)
{
@@ -131,7 +136,7 @@ static PLATFORM_ADD_FILE_WATCH_FN(linux_add_file_watch)
stat_buffer sb;
syscall2(SYS_stat, (iptr)path, (iptr)sb);
- i32 wd = inotify_add_watch(linux_ctx.inotify_fd, (c8 *)path, LINUX_INOTIFY_MASK);
+ i32 wd = syscall3(SYS_inotify_add_watch, linux_ctx.inotify_fd, (iptr)path, LINUX_INOTIFY_MASK);
i32 idx = linux_ctx.file_watch_count++;
ASSERT(idx < ARRAY_COUNT(linux_ctx.file_watches));
@@ -145,15 +150,22 @@ static PLATFORM_ADD_FILE_WATCH_FN(linux_add_file_watch)
static void
dispatch_file_watch_events(PlatformCtx *ctx)
{
+ struct {
+ i32 wd;
+ u32 mask, cookie, len;
+ c8 name[];
+ } *ie;
+
u8 *mem = alloc_(&ctx->platform_memory, 4096, 64, 1);
s8 buf = {.len = 4096, .data = mem};
+
for (;;) {
size rlen = syscall3(SYS_read, ctx->inotify_fd, (iptr)buf.data, buf.len);
if (rlen <= 0)
break;
- struct inotify_event *ie;
+
for (u8 *data = buf.data; data < buf.data + rlen; data += sizeof(*ie) + ie->len) {
- ie = (struct inotify_event *)data;
+ ie = (void *)data;
for (i32 i = 0; i < ctx->file_watch_count; i++) {
linux_file_watch *fw = ctx->file_watches + i;
if (fw->handle == ie->wd) {
@@ -165,11 +177,13 @@ dispatch_file_watch_events(PlatformCtx *ctx)
stat_buffer sb;
syscall2(SYS_stat, (iptr)fw->path, (iptr)sb);
if (fw->inode != STAT_INODE(sb)) {
- inotify_rm_watch(ctx->inotify_fd, fw->handle);
+ syscall2(SYS_inotify_rm_watch, ctx->inotify_fd,
+ (iptr)fw->handle);
fw->inode = STAT_INODE(sb);
- fw->handle = inotify_add_watch(ctx->inotify_fd,
- (c8 *)fw->path,
- LINUX_INOTIFY_MASK);
+ fw->handle = syscall3(SYS_inotify_add_watch,
+ ctx->inotify_fd,
+ (iptr)fw->path,
+ LINUX_INOTIFY_MASK);
file_changed = 1;
}
if (file_changed)
diff --git a/platform_linux_x11.c b/platform_linux_x11.c
@@ -418,7 +418,7 @@ main(i32 argc, char *argv[], char *envp[])
#endif
}
- linux_ctx.inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
+ linux_ctx.inotify_fd = syscall1(SYS_inotify_init1, O_NONBLOCK|O_CLOEXEC);
#ifdef _DEBUG
debug_reload_library((u8 *)DEBUG_LIB_NAME, &linux_ctx);