all repos — mgba @ 762ddb096d103d2e8947c453dc0a1375764e83f2

mGBA Game Boy Advance Emulator

GUI: Handle paths starting with / properly
Jeffrey Pfau jeffrey@endrift.com
Mon, 24 Aug 2015 19:35:44 -0700
commit

762ddb096d103d2e8947c453dc0a1375764e83f2

parent

fb82257d03d8ad01b2353513f11981308ee47126

1 files changed, 10 insertions(+), 1 deletions(-)

jump to
M src/util/gui/file-select.csrc/util/gui/file-select.c

@@ -26,6 +26,10 @@ char* end = strrchr(currentPath, '/');

if (!end) { return; } + if (end == currentPath) { + end[1] = '\0'; + return; + } end[0] = '\0'; if (end[1]) { return;

@@ -85,7 +89,12 @@ FileListDeinit(&currentFiles);

return false; } if (newInput & (1 << GUI_INPUT_SELECT)) { - snprintf(currentPath, sizeof(currentPath), "%s%c%s", currentPath, '/', *FileListGetPointer(&currentFiles, fileIndex)); + size_t len = strlen(currentPath); + const char* sep = PATH_SEP; + if (currentPath[len - 1] == *sep) { + sep = ""; + } + snprintf(currentPath, sizeof(currentPath), "%s%s%s", currentPath, sep, *FileListGetPointer(&currentFiles, fileIndex)); if (!_refreshDirectory(currentPath, &currentFiles)) { strncpy(outPath, currentPath, outLen); return true;