# HG changeset patch # User Michael Pavone # Date 1706156297 28800 # Node ID 794ba17f07166d15d5341c107bb0f19e16ed4d9f # Parent 767ec72acca74a132934b35dab88db47a4df5043 Make termhelper work when current working directory is not the one that contains blastem diff -r 767ec72acca7 -r 794ba17f0716 terminal.c --- a/terminal.c Wed Jan 24 18:51:44 2024 -0800 +++ b/terminal.c Wed Jan 24 20:18:17 2024 -0800 @@ -26,6 +26,7 @@ void init_terminal() { +#ifndef IS_LIB if (!init_done) { if (!(isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))) { #ifndef __APPLE__ @@ -50,11 +51,13 @@ warning("Failed to fork for terminal spawn"); } else if (!child) { //child process, exec our terminal emulator + char *termhelper = bundled_file_path("termhelper"); #ifdef __APPLE__ - execlp("open", "open", "./termhelper", NULL); + execlp("open", "open", termhelper, NULL); #else - execlp(term, term, "-title", "BlastEm Debugger", "-e", "./termhelper", NULL); + execlp(term, term, "-title", "BlastEm Debugger", "-e", termhelper, NULL); #endif + free(termhelper); } else { //connect to the FIFOs, these will block so order is important open(INPUT_PATH, O_RDONLY); @@ -68,4 +71,5 @@ init_done = 1; } +#endif } diff -r 767ec72acca7 -r 794ba17f0716 util.c --- a/util.c Wed Jan 24 18:51:44 2024 -0800 +++ b/util.c Wed Jan 24 20:18:17 2024 -0800 @@ -1016,21 +1016,29 @@ #else #ifndef IS_LIB -char *read_bundled_file(char *name, uint32_t *sizeret) +char *bundled_file_path(char *name) { #ifdef DATA_PATH char *data_dir = DATA_PATH; #else char *data_dir = get_exe_dir(); if (!data_dir) { + return NULL; + } +#endif + char const *pieces[] = {data_dir, PATH_SEP, name}; + return alloc_concat_m(3, pieces); +} + +char *read_bundled_file(char *name, uint32_t *sizeret) +{ + char *path = bundled_file_path(name); + if (!path) { if (sizeret) { *sizeret = -1; } return NULL; } -#endif - char const *pieces[] = {data_dir, PATH_SEP, name}; - char *path = alloc_concat_m(3, pieces); FILE *f = fopen(path, "rb"); free(path); if (!f) { diff -r 767ec72acca7 -r 794ba17f0716 util.h --- a/util.h Wed Jan 24 18:51:44 2024 -0800 +++ b/util.h Wed Jan 24 20:18:17 2024 -0800 @@ -66,6 +66,8 @@ char const *get_config_dir(); //Returns an appropriate path for saving non-config data like savestates char const *get_userdata_dir(); +//Returns the path of a file bundled with the executable +char *bundled_file_path(char *name); //Reads a file bundled with the executable char *read_bundled_file(char *name, uint32_t *sizeret); //Retunrs an array of normal files and directories residing in a directory