From 2900092e4e06be77108ed6b8a66c7aa673d0b494 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 25 Nov 2017 13:57:38 -0800 Subject: Fix directory navigation in ROM file chooser in Nuklear UI --HG-- branch : nuklear_ui --- paths.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'paths.c') diff --git a/paths.c b/paths.c index c3c4ad9..9f7afbd 100644 --- a/paths.c +++ b/paths.c @@ -101,3 +101,43 @@ void get_initial_browse_path(char **dst) *dst = replace_vars(*dst, vars, 1); tern_free(vars); } + +char *path_append(char *base, char *suffix) +{ + if (!strcmp(suffix, "..")) { +#ifdef _WIN32 + //handle transition from root of a drive to virtual root + if (base[1] == ':' && !base[2]) { + return strdup(PATH_SEP) + } +#endif + size_t len = strlen(base); + while (len > 0) { + --len; + if (is_path_sep(base[len])) { + if (!len) { + //special handling for / + len++; + } + char *ret = malloc(len+1); + memcpy(ret, base, len); + ret[len] = 0; + return ret; + } + } + return strdup(PATH_SEP); + } else { +#ifdef _WIN32 + if (base[0] == PATH_SEP[0] && !base[1]) { + //handle transition from virtual root to root of a drive + return strdup(suffix); + } +#endif + if (is_path_sep(base[strlen(base) - 1])) { + return alloc_concat(base, suffix); + } else { + char const *pieces[] = {base, PATH_SEP, suffix}; + return alloc_concat_m(3, pieces); + } + } +} -- cgit v1.2.3