commit fd7aa71

Devine Lu Linvega  ·  2025-03-14 17:40:53 +0000 UTC
parent 5e96370
Cleanup
2 files changed,  +22, -15
+19, -13
 1@@ -44,13 +44,16 @@ static UxnFile ufs[2];
 2 static Uint8 dirbuf[0x10000], *_dirbuf = dirbuf;
 3 
 4 static void
 5-make_pathfile(char *res, char *path, char *file)
 6+make_pathfile(char *pathbuf, const char *filepath, const char *basename)
 7 {
 8 	char c = '/';
 9-	while(*path) c = *path++, *res = c, res++;
10-	if(c != DIRCHAR) *res = DIRCHAR, res++;
11-	while(*file) *res = *file++, res++;
12-	*res = 0;
13+	while(*filepath)
14+		c = *filepath++, *pathbuf = c, pathbuf++;
15+	if(c != DIRCHAR)
16+		*pathbuf = DIRCHAR, pathbuf++;
17+	while(*basename)
18+		*pathbuf = *basename++, pathbuf++;
19+	*pathbuf = 0;
20 }
21 
22 static int
23@@ -93,9 +96,13 @@ put_stat(Uint8 *dest, int len, int size, int err, int dir, int capsize)
24 static int
25 put_statfile(Uint8 *dest, const char *filepath, const char *basename)
26 {
27+	int err, dir;
28 	struct stat st;
29 	Uint8 *anchor = dest;
30-	int err = stat(filepath, &st), dir = S_ISDIR(st.st_mode);
31+	char pathbuf[0x2000];
32+	make_pathfile(pathbuf, filepath, basename);
33+	err = stat(pathbuf, &st);
34+	dir = S_ISDIR(st.st_mode);
35 	dest += put_stat(dest, 4, st.st_size, err, dir, 1);
36 	dest += put_text(dest, " ");
37 	dest += put_text(dest, basename);
38@@ -104,7 +111,7 @@ put_statfile(Uint8 *dest, const char *filepath, const char *basename)
39 }
40 
41 static int
42-put_fdir(Uint8 *dest, unsigned int len, const char *filepath, DIR *dir)
43+put_fdir(Uint8 *dest, int len, const char *filepath, DIR *dir)
44 {
45 	int i;
46 	struct dirent *de = readdir(dir);
47@@ -112,11 +119,8 @@ put_fdir(Uint8 *dest, unsigned int len, const char *filepath, DIR *dir)
48 		char *name = de->d_name;
49 		if(name[0] == '.' && (name[1] == '.' || name[1] == '\0'))
50 			continue;
51-		else {
52-			static char res[0x2000];
53-			make_pathfile(res, (char *)filepath, name);
54-			_dirbuf += put_statfile(_dirbuf, res, name);
55-		}
56+		else
57+			_dirbuf += put_statfile(_dirbuf, filepath, name);
58 	}
59 	for(i = 0; i < len && dirbuf[i]; i++)
60 		dest[i] = dirbuf[i];
61@@ -225,10 +229,12 @@ file_write(int id, Uint16 addr, int len, Uint8 flags)
62 static int
63 file_stat(int id, Uint16 addr, int len)
64 {
65+	int err, dir;
66 	struct stat st;
67 	if(file_not_ready(id))
68 		return 0;
69-	int err = stat(ufs[id].filepath, &st), dir = S_ISDIR(st.st_mode);
70+	err = stat(ufs[id].filepath, &st);
71+	dir = S_ISDIR(st.st_mode);
72 	return put_stat(&uxn.ram[addr], len, st.st_size, err, dir, 0);
73 }
74 
+3, -2
 1@@ -222,6 +222,7 @@ display_init(void)
 2 static int
 3 emu_run(void)
 4 {
 5+	int has_input, has_eof;
 6 	char expirations[8], coninp[CONINBUFSIZE];
 7 	struct pollfd fds[3];
 8 	static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
 9@@ -248,8 +249,8 @@ emu_run(void)
10 				XPutImage(display, window, DefaultGC(display, 0), ximage, x, y, x, y, w, h);
11 			}
12 		}
13-		int has_input = fds[2].revents & POLLIN;
14-		int has_eof = fds[2].revents & POLLHUP;
15+		has_input = fds[2].revents & POLLIN;
16+		has_eof = fds[2].revents & POLLHUP;
17 		if(has_input || has_eof) {
18 			int i = 1, n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);
19 			for(i = 0, coninp[n] = 0; i < n; i++)