From: kub Date: Wed, 14 Feb 2024 22:00:45 +0000 (+0100) Subject: add .. to dir listing if it is missing X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d23f5773e1ab00d7d5c702f8a01bde401dde48de;p=libpicofe.git add .. to dir listing if it is missing --- diff --git a/menu.c b/menu.c index 04fb381..5eb48b9 100644 --- a/menu.c +++ b/menu.c @@ -475,7 +475,7 @@ static int me_id2offset(const menu_entry *ent, menu_id id) static void me_enable(menu_entry *entries, menu_id id, int enable) { int i = me_id2offset(entries, id); - entries[i].enabled = enable; + entries[i].enabled = !!enable; } static int me_count(const menu_entry *ent) @@ -1076,6 +1076,16 @@ rescan: if (n > 1) qsort(namelist, n, sizeof(namelist[0]), scandir_cmp); + // add ".." if it's somehow not there + if (n == 0 || strcmp(namelist[0]->d_name, "..")) { + struct dirent *dotdot = malloc(sizeof(*dotdot)); + *dotdot = (struct dirent) { .d_name="..", .d_type=DT_DIR }; + namelist = realloc(namelist, (n+1)*sizeof(*namelist)); + memmove(namelist+1, namelist, n*sizeof(*namelist)); + namelist[0] = dotdot; + n++; + } + // try to find selected file sel = 0; if (sel_fname[0] != 0) {