From 7abda487de0fdbad67f1d1f56bca04f7ce7a6a55 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Wed, 4 May 2016 22:11:48 -0700 Subject: Allow navigating to the root directory on Unix-like systems --- menu.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'menu.c') diff --git a/menu.c b/menu.c index 6d8786e..30a42e2 100644 --- a/menu.c +++ b/menu.c @@ -193,17 +193,26 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value) copy_string_from_guest(m68k, dst, buf, sizeof(buf)); if (!strcmp(buf, "..")) { size_t len = strlen(menu->curpath); - while (len > 1) { + while (len > 0) { --len; if (is_path_sep(menu->curpath[len])) { - menu->curpath[len] = 0; + if (!len) { + //special handling for / + menu->curpath[len+1] = 0; + } else { + menu->curpath[len] = 0; + } break; } } } else { char *tmp = menu->curpath; - char const *pieces[] = {menu->curpath, PATH_SEP, buf}; - menu->curpath = alloc_concat_m(3, pieces); + if (is_path_sep(menu->curpath[strlen(menu->curpath) - 1])) { + menu->curpath = alloc_concat(menu->curpath, buf); + } else { + char const *pieces[] = {menu->curpath, PATH_SEP, buf}; + menu->curpath = alloc_concat_m(3, pieces); + } free(tmp); } break; -- cgit v1.2.3