add .. to dir listing if it is missing

This commit is contained in:
kub 2024-02-14 23:00:45 +01:00
parent ff8abdddba
commit d23f5773e1

12
menu.c
View file

@ -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) {