# HG changeset patch # User Michael Pavone # Date 1671805421 28800 # Node ID bc68560b4a04fb75d8c012833c65e9363b73da9a # Parent 86dfcf3f418a08ffb3fd279a8757e2b503a45c11 Fix bug when loading cue sheet without leading path diff -r 86dfcf3f418a -r bc68560b4a04 blastem.c --- a/blastem.c Fri Dec 23 05:49:04 2022 -0800 +++ b/blastem.c Fri Dec 23 06:23:41 2022 -0800 @@ -23,6 +23,7 @@ #include "gdb_remote.h" #include "gst.h" #include "util.h" +#include "paths.h" #include "romdb.h" #include "terminal.h" #include "arena.h" @@ -167,6 +168,9 @@ } dst->extension = ext; dst->dir = path_dirname(filename); + if (!dst->dir) { + dst->dir = path_current_dir(); + } dst->name = basename_no_extension(filename); dst->size = out_size; zip_close(z); @@ -253,6 +257,9 @@ ret = (uint32_t)readsize; } dst->dir = path_dirname(filename); + if (!dst->dir) { + dst->dir = path_current_dir(); + } dst->name = basename_no_extension(filename); dst->extension = ext; dst->size = ret; diff -r 86dfcf3f418a -r bc68560b4a04 paths.c --- a/paths.c Fri Dec 23 05:49:04 2022 -0800 +++ b/paths.c Fri Dec 23 06:23:41 2022 -0800 @@ -2,6 +2,12 @@ #include #include "blastem.h" #include "util.h" +#ifdef _WIN32 +#include +#else +#include +#include +#endif static char **current_path; @@ -140,3 +146,34 @@ } } } + +char *path_current_dir(void) +{ + size_t size = 128; + char *res = malloc(size); + for (;;) { +#ifdef _WIN32 + DWORD actual = GetCurrentDirectoryA(size, res); + if (actual > size) { + res = realloc(res, actual); + size = actual; + } else { + return res; + } +#else + errno = 0; + char *tmp = getcwd(res, size); + if (!tmp) { + if (errno == ERANGE) { + size *= 2; + res = realloc(res, size); + } else { + free(res); + return NULL; + } + } else { + return res; + } +#endif + } +} diff -r 86dfcf3f418a -r bc68560b4a04 paths.h --- a/paths.h Fri Dec 23 05:49:04 2022 -0800 +++ b/paths.h Fri Dec 23 06:23:41 2022 -0800 @@ -3,5 +3,6 @@ void get_initial_browse_path(char **dst); char *path_append(const char *base, const char *suffix); +char *path_current_dir(void); #endif //PATHS_H_ \ No newline at end of file