Rewrote get_entry

This commit is contained in:
Devine Lu Linvega 2021-11-07 12:26:37 -05:00
parent dee04ff44a
commit 42d0f65d12
1 changed files with 9 additions and 16 deletions

View File

@ -31,8 +31,6 @@ static enum { IDLE,
DIR_READ } state; DIR_READ } state;
static struct dirent *de; static struct dirent *de;
static char hex[] = "0123456789abcdef";
static void static void
reset(void) reset(void)
{ {
@ -52,21 +50,16 @@ static Uint16
get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero) get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero)
{ {
struct stat st; struct stat st;
if(len < strlen(basename) + 7) return 0; if(len < strlen(basename) + 7)
memcpy(p, "???? ", 5); return 0;
strcpy(p + 5, basename);
strcat(p, "\n");
if(stat(pathname, &st)) if(stat(pathname, &st))
return fail_nonzero ? strlen(p) : 0; return fail_nonzero ? snprintf(p, len, "!!!! %s\n", basename) : 0;
if(S_ISDIR(st.st_mode)) { else if(S_ISDIR(st.st_mode))
memcpy(p, "---- ", 5); return snprintf(p, len, "---- %s\n", basename);
} else if(st.st_size < 0x10000) { else if(st.st_size < 0x10000)
p[0] = hex[(st.st_size >> 12) & 0xf]; return snprintf(p, len, "%04x %s\n", (Uint16)st.st_size, basename);
p[1] = hex[(st.st_size >> 8) & 0xf]; else
p[2] = hex[(st.st_size >> 4) & 0xf]; return snprintf(p, len, "???? %s\n", basename);
p[3] = hex[(st.st_size >> 0) & 0xf];
}
return strlen(p);
} }
static Uint16 static Uint16