Commit: 420ff9fcd22a6b803ec6ae2ee8182f3953f509f7
Parent: cf9f08e76699db10a7556d17c1b41ea11cb57b00
Author: Randy Palamar
Date: Wed, 16 Oct 2024 22:52:15 -0600
use same dirent name length trick in posix layer
also cleanup some pointless code
Diffstat:
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/jdict.c b/jdict.c
@@ -56,9 +56,6 @@ typedef struct {
#define YOMI_TOKS_PER_ENT 10
-/* buffer length for interactive mode */
-#define BUFLEN 256
-
/* Number of hash table slots (1 << HT_EXP) */
#define HT_EXP 20
diff --git a/platform_linux.c b/platform_linux.c
@@ -29,10 +29,7 @@ typedef struct {
__attribute((section(".text.memset")))
void *memset(void *d, int c, size_t n)
{
- u8 *bytes = d;
- for (size_t i = 0; i < n; i++)
- bytes[i] = c;
- return d;
+ return mem_clear(d, c, n);
}
static void
diff --git a/platform_posix.c b/platform_posix.c
@@ -109,18 +109,19 @@ os_get_valid_file(PathStream *ps, s8 match_prefix, Arena *a, u32 arena_flags)
while ((dent = readdir(ps->dirfd)) != NULL) {
if (dent->d_type == DT_REG) {
b32 valid = 1;
+ /* NOTE: technically this contains extra NULs but it doesn't matter
+ * for this purpose. We need NUL terminated to call read() */
+ s8 name = {.len = dent->d_reclen - 2 - offsetof(struct dirent, d_name),
+ .s = (u8 *)dent->d_name};
for (size i = 0; i < match_prefix.len; i++) {
- if (match_prefix.s[i] != dent->d_name[i]) {
+ if (match_prefix.s[i] != name.s[i]) {
valid = 0;
break;
}
}
if (valid) {
Stream dir_name = *ps->dir_name;
- s8 d_name = cstr_to_s8(dent->d_name);
- /* NOTE: include NUL */
- d_name.len++;
- stream_append_s8(&dir_name, d_name);
+ stream_append_s8(&dir_name, name);
result = os_read_whole_file((char *)dir_name.data, a,
arena_flags);
break;