1515
1616#if FF_HAVE_WORDEXP
1717 #include <wordexp.h>
18- #elif FF_HAVE_GLOB
19- #warning "<wordexp.h> is not available, use <glob.h> instead"
20- #include <glob.h>
2118#else
22- #warning "Neither <wordexp.h> nor <glob.h> is available"
19+ #warning "<wordexp.h> is not available, use glob(3) instead"
20+ #include <glob.h>
2321#endif
2422
2523static void createSubfolders (const char * fileName )
@@ -136,14 +134,14 @@ bool ffAppendFileBufferRelative(int dfd, const char* fileName, FFstrbuf* buffer)
136134 return ffAppendFDBuffer (fd , buffer );
137135}
138136
139- bool ffPathExpandEnv (FF_MAYBE_UNUSED const char * in , FF_MAYBE_UNUSED FFstrbuf * out )
137+ bool ffPathExpandEnv (const char * in , FFstrbuf * out )
140138{
141139 bool result = false;
142140
143- #if FF_HAVE_WORDEXP // https://github.com/termux/termux-packages/pull/7056
141+ #if FF_HAVE_WORDEXP
144142
145143 wordexp_t exp ;
146- if (wordexp (in , & exp , 0 ) != 0 )
144+ if (wordexp (in , & exp , 0 ) != 0 ) // WARN: 0 = no safety flags; command substitution allowed
147145 return false;
148146
149147 if (exp .we_wordc >= 1 )
@@ -154,16 +152,23 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o
154152
155153 wordfree (& exp );
156154
157- #elif FF_HAVE_GLOB
155+ #else
158156
159157 glob_t gb ;
160- if (glob (in , GLOB_NOSORT | GLOB_TILDE , NULL , & gb ) != 0 )
158+ if (glob (in , GLOB_NOSORT
159+ #ifdef GLOB_TILDE
160+ | GLOB_TILDE
161+ #endif
162+ #ifdef GLOB_BRACE
163+ | GLOB_BRACE
164+ #endif
165+ , NULL , & gb ) != 0 )
161166 return false;
162167
163- if (gb .gl_matchc >= 1 )
168+ if (gb .gl_pathc >= 1 )
164169 {
165170 result = true;
166- ffStrbufSetS (out , gb .gl_pathv [gb .gl_matchc > 1 ? ffTimeGetNow () % gb .gl_matchc : 0 ]);
171+ ffStrbufSetS (out , gb .gl_pathv [gb .gl_pathc > 1 ? ffTimeGetNow () % ( unsigned ) gb .gl_pathc : 0 ]);
167172 }
168173
169174 globfree (& gb );
0 commit comments