commit aba5a7e
Devine Lu Linvega
·
2025-01-22 19:44:15 +0000 UTC
parent fc0e968
Progress on file device
1 files changed,
+10,
-31
+10,
-31
1@@ -77,7 +77,7 @@ put_size(Uint8 *dest, Uint16 len, off_t size)
2 }
3
4 static Uint16
5-put_stat(char *dest, Uint16 len, int size, int err, int dir, int capsize)
6+put_stat(Uint8 *dest, Uint16 len, int size, int err, int dir, int capsize)
7 {
8 if(err)
9 return put_fill(dest, len, '!');
10@@ -90,7 +90,7 @@ put_stat(char *dest, Uint16 len, int size, int err, int dir, int capsize)
11 }
12
13 static Uint16
14-put_statfile(char *dest, Uint16 len, const char *filepath, const char *basename)
15+put_statfile(Uint8 *dest, Uint16 len, const char *filepath, const char *basename)
16 {
17 int err, dir;
18 struct stat st;
19@@ -99,7 +99,7 @@ put_statfile(char *dest, Uint16 len, const char *filepath, const char *basename)
20 err = stat(filepath, &st);
21 dir = S_ISDIR(st.st_mode);
22 dest += put_stat(dest, 4, st.st_size, err, dir, 1);
23- return snprintf(dest, len, dir ? " %s/\n" : " %s\n", basename) + 4;
24+ return snprintf((char *)dest, len, dir ? " %s/\n" : " %s\n", basename) + 4;
25 }
26
27 static void
28@@ -114,39 +114,18 @@ file_reset(UxnFile *c)
29 }
30
31 static Uint16
32-file_read_dir(UxnFile *c, char *dest, Uint16 len)
33+file_read_dir(UxnFile *c, Uint8 *dest, Uint16 len)
34 {
35+ Uint8 *p = dest;
36+ static char pathname[0x2000];
37 struct dirent *de = readdir(c->dir);
38- static char pathname[4352];
39- char *p = dest;
40 for(; de != NULL; de = readdir(c->dir)) {
41- Uint16 n;
42- if(de->d_name[0] == '.' && de->d_name[1] == '\0')
43+ if(de->d_name[0] == '.' && de->d_name[1] == 0)
44 continue;
45- if(strcmp(de->d_name, "..") == 0) {
46- /* hide "sandbox/.." */
47- char cwd[PATH_MAX] = {'\0'}, *t;
48- /* Note there's [currently] no way of chdir()ing from uxn, so $PWD
49- * is always the sandbox top level. */
50- getcwd(cwd, sizeof(cwd));
51- /* We already checked that c->filepath exists so don't need a wrapper. */
52- t = realpath(c->filepath, NULL);
53- if(strcmp(cwd, t) == 0) {
54- free(t);
55- continue;
56- }
57- free(t);
58- }
59- if(strlen(c->filepath) + 1 + strlen(de->d_name) < sizeof(pathname))
60- snprintf(pathname, sizeof(pathname), "%s/%s", c->filepath, de->d_name);
61- else
62- pathname[0] = '\0';
63- n = put_statfile(p, len, pathname, de->d_name);
64- if(!n) break;
65- p += n;
66- len -= n;
67+ snprintf(pathname, 0x2000, c->filepath[0] == '.' ? "%s/%s" : "%s%s", c->filepath, de->d_name);
68+ dest += put_statfile(dest, len, pathname, de->d_name);
69 }
70- return p - dest;
71+ return dest - p;
72 }
73
74 static char *