diff --git a/src/compat/compat.h b/src/compat/compat.h index daf177551..60daba001 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -119,20 +119,25 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *request, struct timespec *remain); +__attribute__ ((nonnull (2))) __attribute__ ((malloc)) static inline char* -notcurses_data_path(const char* f){ - char* datadir = notcurses_data_dir(); - if(datadir == NULL){ - return NULL; +notcurses_data_path(const char* ddir, const char* f){ + char* datadir = NULL; + if(ddir == NULL){ + datadir = notcurses_data_dir(); + if(datadir == NULL){ + return NULL; + } + ddir = datadir; } - const size_t dlen = strlen(datadir); + const size_t dlen = strlen(ddir); // cast is for benefit of c++ callers, sigh char* path = (char*)malloc(dlen + 1 + strlen(f) + 1); if(path == NULL){ free(datadir); return NULL; } - strcpy(path, datadir); + strcpy(path, ddir); free(datadir); path[dlen] = path_separator(); strcpy(path + dlen + 1, f); diff --git a/src/demo/demo.c b/src/demo/demo.c index 99784d376..627c153f5 100644 --- a/src/demo/demo.c +++ b/src/demo/demo.c @@ -44,7 +44,7 @@ const demoresult* demoresult_lookup(int idx){ } char* find_data(const char* datum){ - return notcurses_data_path(datum); + return notcurses_data_path(datadir, datum); } float delaymultiplier = 1; @@ -510,7 +510,6 @@ int main(int argc, char** argv){ sigaddset(&sigmask, SIGWINCH); pthread_sigmask(SIG_BLOCK, &sigmask, NULL); #endif - datadir = notcurses_data_dir(); const char* spec; FILE* json = NULL; // emit JSON summary to this file? (-J) notcurses_options nopts = {}; diff --git a/src/tetris/main.cpp b/src/tetris/main.cpp index 4f486cf45..23896a6cc 100644 --- a/src/tetris/main.cpp +++ b/src/tetris/main.cpp @@ -17,8 +17,8 @@ std::mutex ncmtx; -const std::string BackgroundFile = notcurses_data_path("tetris-background.jpg"); -const std::string LogoFile = notcurses_data_path("notcurses.png"); +const std::string BackgroundFile = notcurses_data_path(nullptr, "tetris-background.jpg"); +const std::string LogoFile = notcurses_data_path(nullptr, "notcurses.png"); using namespace std::chrono_literals;