From 57dfcdf71786a31b787772da960ba8c4b020d59a Mon Sep 17 00:00:00 2001 From: phoebos Date: Fri, 29 Jul 2022 13:06:20 +0100 Subject: [PATCH] don't print .. at sandbox top level --- src/devices/file.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/devices/file.c b/src/devices/file.c index dbcb1a1..87cf9a2 100644 --- a/src/devices/file.c +++ b/src/devices/file.c @@ -82,6 +82,17 @@ file_read_dir(UxnFile *c, char *dest, Uint16 len) Uint16 n; if(c->de->d_name[0] == '.' && c->de->d_name[1] == '\0') continue; + if(strcmp(c->de->d_name, "..") == 0) { + /* hide "sandbox/.." */ + char cwd[PATH_MAX] = {'\0'}, t[PATH_MAX] = {'\0'}; + /* Note there's [currently] no way of chdir()ing from uxn, so $PWD + * is always the sandbox top level. */ + getcwd(cwd, sizeof(cwd)); + /* We already checked that c->current_filename exists so don't need a wrapper. */ + realpath(c->current_filename, t); + if (strcmp(cwd, t) == 0) + continue; + } if(strlen(c->current_filename) + 1 + strlen(c->de->d_name) < sizeof(pathname)) sprintf(pathname, "%s/%s", c->current_filename, c->de->d_name); else