jdict

command line tool for looking up terms in yomidict dictionaries
git clone anongit@rnpnr.xyz:jdict.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 68774a77b36018c502c243f545aa5808f9aa56f0
Parent: 22bae2b0cf06daa76a593ac71afa9d21722e12fc
Author: Randy Palamar
Date:   Thu, 17 Oct 2024 11:03:28 -0600

linux_amd64: use getdents64 directly rather than the 32-bit wrapper

Diffstat:
Mplatform_linux.c | 5+++--
Mplatform_linux_amd64.c | 19++++++++++---------
2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/platform_linux.c b/platform_linux.c @@ -147,7 +147,8 @@ os_get_valid_file(PathStream *ps, s8 match_prefix, Arena *a, u32 arena_flags) if (lds) { for (;;) { if (lds->buf_pos >= lds->buf_end) { - u64 ret = syscall3(SYS_getdents, lds->fd, (iptr)lds->buf, sizeof(lds->buf)); + u64 ret = syscall3(SYS_getdents64, lds->fd, (iptr)lds->buf, + sizeof(lds->buf)); if (ret > -4096UL) { stream_append_s8(&error_stream, s8("os_get_valid_file: SYS_getdents")); die(&error_stream); @@ -158,7 +159,7 @@ os_get_valid_file(PathStream *ps, s8 match_prefix, Arena *a, u32 arena_flags) lds->buf_pos = 0; } u16 record_len = *(u16 *)(lds->buf + lds->buf_pos + DIRENT_RECLEN_OFF); - u8 type = lds->buf[lds->buf_pos + record_len - 1]; + u8 type = lds->buf[lds->buf_pos + DIRENT_TYPE_OFF]; /* NOTE: technically this contains extra NULs but it doesn't matter * for this purpose. We need NUL terminated to call SYS_read */ s8 name = {.len = record_len - 2 - DIRENT_NAME_OFF, diff --git a/platform_linux_amd64.c b/platform_linux_amd64.c @@ -8,14 +8,14 @@ #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_exit 60 -#define SYS_getdents 78 +#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_exit 60 +#define SYS_getdents64 217 #define PAGESIZE 4096 @@ -23,7 +23,8 @@ #define STAT_SIZE_OFF 48 #define DIRENT_RECLEN_OFF 16 -#define DIRENT_NAME_OFF 18 +#define DIRENT_TYPE_OFF 18 +#define DIRENT_NAME_OFF 19 #include "platform_linux.c"