diff --git a/CHANGELOG.md b/CHANGELOG.md index 7496f9104..6abea1276 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Bugfixes: * Fixes incorrect glibc dependency in polyfilled DEB packages (#1983, Linux) * Fixes corrupted binaries in polyfilled RPM packages (#1990, Linux) * Fixes crashes on ancient Android kernels (#1993, Disk, Android) +* Fixes incorrect usage of `glob(3)` (OpenBSD) * Prefers resolutions reported by RandR mode info, fixing incorrect resolutions on XFCE when DPI scaling is enabled (Display, Linux) * Various code cleanups and minor fixes diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c4071ea0..4e980fd1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1743,6 +1743,7 @@ elseif(ANDROID) target_link_libraries(libfastfetch PRIVATE "m" ) + # https://github.com/termux/termux-packages/pull/7056 CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC) if(HAVE_LIBANDROID_WORDEXP_STATIC) target_link_libraries(libfastfetch @@ -1819,10 +1820,6 @@ 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 90560f3f6..cd4f3fae5 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -15,11 +15,9 @@ #if FF_HAVE_WORDEXP #include -#elif FF_HAVE_GLOB - #warning " is not available, use instead" - #include #else - #warning "Neither nor is available" + #warning " is not available, use glob(3) instead" + #include #endif static void createSubfolders(const char* fileName) @@ -136,14 +134,14 @@ bool ffAppendFileBufferRelative(int dfd, const char* fileName, FFstrbuf* buffer) return ffAppendFDBuffer(fd, buffer); } -bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out) +bool ffPathExpandEnv(const char* in, FFstrbuf* out) { bool result = false; - #if FF_HAVE_WORDEXP // https://github.com/termux/termux-packages/pull/7056 + #if FF_HAVE_WORDEXP wordexp_t exp; - if (wordexp(in, &exp, 0) != 0) + if (wordexp(in, &exp, 0) != 0) // WARN: 0 = no safety flags; command substitution allowed return false; if (exp.we_wordc >= 1) @@ -154,16 +152,23 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o wordfree(&exp); - #elif FF_HAVE_GLOB + #else glob_t gb; - if (glob(in, GLOB_NOSORT | GLOB_TILDE, NULL, &gb) != 0) + if (glob(in, GLOB_NOSORT + #ifdef GLOB_TILDE + | GLOB_TILDE + #endif + #ifdef GLOB_BRACE + | GLOB_BRACE + #endif + , NULL, &gb) != 0) return false; - if (gb.gl_matchc >= 1) + if (gb.gl_pathc >= 1) { result = true; - ffStrbufSetS(out, gb.gl_pathv[gb.gl_matchc > 1 ? ffTimeGetNow() % gb.gl_matchc : 0]); + ffStrbufSetS(out, gb.gl_pathv[gb.gl_pathc > 1 ? ffTimeGetNow() % (unsigned) gb.gl_pathc : 0]); } globfree(&gb);