diff --git a/CMakeLists.txt b/CMakeLists.txt index f8ab5015c..4ee1a67a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1385,6 +1385,10 @@ if(NOT WIN32) if(HAVE_WORDEXP) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WORDEXP=1) endif() + CHECK_INCLUDE_FILE("glob.h" HAVE_GLOB) + if(HAVE_GLOB) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_GLOB=1) + endif() if(ENABLE_THREADS AND CMAKE_USE_PTHREADS_INIT) CHECK_INCLUDE_FILE("pthread_np.h" HAVE_PTHREAD_NP) if(HAVE_PTHREAD_NP) diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index 957789c69..f08e9140a 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -14,8 +14,11 @@ #if FF_HAVE_WORDEXP #include +#elif FF_HAVE_GLOB + #warning " is not available, use instead + #include #else - #warning " not available" + #warning "Neither nor is available" #endif static void createSubfolders(const char* fileName) @@ -121,7 +124,7 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o #if FF_HAVE_WORDEXP // https://github.com/termux/termux-packages/pull/7056 wordexp_t exp; - if(wordexp(in, &exp, 0) != 0) + if (wordexp(in, &exp, 0) != 0) return false; if (exp.we_wordc == 1) @@ -132,6 +135,20 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o wordfree(&exp); + #elif FF_HAVE_GLOB + + glob_t gb; + if (glob(in, GLOB_NOSORT | GLOB_TILDE, NULL, &gb) != 0) + return false; + + if (gb.gl_matchc == 1) + { + result = true; + ffStrbufSetS(out, gb.gl_pathv[0]); + } + + globfree(&gb); + #endif return result;