Skip to content

Commit 716bfe7

Browse files
committed
Global: use glob(3) if wordexp(3) is not available
1 parent 84fc5b4 commit 716bfe7

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,10 @@ if(NOT WIN32)
13851385
if(HAVE_WORDEXP)
13861386
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WORDEXP=1)
13871387
endif()
1388+
CHECK_INCLUDE_FILE("glob.h" HAVE_GLOB)
1389+
if(HAVE_GLOB)
1390+
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_GLOB=1)
1391+
endif()
13881392
if(ENABLE_THREADS AND CMAKE_USE_PTHREADS_INIT)
13891393
CHECK_INCLUDE_FILE("pthread_np.h" HAVE_PTHREAD_NP)
13901394
if(HAVE_PTHREAD_NP)

src/common/io/io_unix.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414

1515
#if FF_HAVE_WORDEXP
1616
#include <wordexp.h>
17+
#elif FF_HAVE_GLOB
18+
#warning "<wordexp.h> is not available, use <glob.h> instead
19+
#include <glob.h>
1720
#else
18-
#warning "<wordexp.h> not available"
21+
#warning "Neither <wordexp.h> nor <glob.h> is available"
1922
#endif
2023

2124
static void createSubfolders(const char* fileName)
@@ -121,7 +124,7 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o
121124
#if FF_HAVE_WORDEXP // https://github.com/termux/termux-packages/pull/7056
122125

123126
wordexp_t exp;
124-
if(wordexp(in, &exp, 0) != 0)
127+
if (wordexp(in, &exp, 0) != 0)
125128
return false;
126129

127130
if (exp.we_wordc == 1)
@@ -132,6 +135,20 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o
132135

133136
wordfree(&exp);
134137

138+
#elif FF_HAVE_GLOB
139+
140+
glob_t gb;
141+
if (glob(in, GLOB_NOSORT | GLOB_TILDE, NULL, &gb) != 0)
142+
return false;
143+
144+
if (gb.gl_matchc == 1)
145+
{
146+
result = true;
147+
ffStrbufSetS(out, gb.gl_pathv[0]);
148+
}
149+
150+
globfree(&gb);
151+
135152
#endif
136153

137154
return result;

0 commit comments

Comments
 (0)