Skip to content

Commit

Permalink
Merge pull request #521 from fastfetch-cli/dev
Browse files Browse the repository at this point in the history
Fix the `<wordexp.h>` not found compiler error on Android
  • Loading branch information
CarterLi authored Aug 14, 2023
2 parents 0291f35 + 86dffe7 commit e19242d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,6 @@ if(WIN32)
target_compile_definitions(libfastfetch PUBLIC WIN32_LEAN_AND_MEAN=1)
endif()

CHECK_INCLUDE_FILE("utmpx.h" HAVE_UTMPX_H)
if(HAVE_UTMPX_H)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_UTMPX_H)
endif()

if(HAVE_WCWIDTH)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WCWIDTH)
endif()
Expand Down Expand Up @@ -829,6 +824,20 @@ elseif(BSD)
target_link_libraries(libfastfetch
PRIVATE "usbhid"
)
elseif(ANDROID)
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)
if(HAVE_LIBANDROID_WORDEXP_STATIC)
target_link_libraries(libfastfetch
PRIVATE -l:libandroid-wordexp.a
)
else()
CHECK_LIBRARY_EXISTS(android-wordexp wordexp "" HAVE_LIBANDROID_WORDEXP)
if(HAVE_LIBANDROID_WORDEXP)
target_link_libraries(libfastfetch
PRIVATE android-wordexp
)
endif()
endif()
endif()

target_include_directories(libfastfetch
Expand Down
11 changes: 10 additions & 1 deletion src/common/io/io_unix.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "io.h"
#include "util/stringUtils.h"
#include "util/unused.h"

#include <fcntl.h>
#include <sys/stat.h>
#include <termios.h>
#include <poll.h>
#include <dirent.h>

#if __has_include(<wordexp.h>)
#include <wordexp.h>
#endif

static void createSubfolders(const char* fileName)
{
Expand Down Expand Up @@ -108,9 +112,12 @@ bool ffPathExists(const char* path, FFPathType type)
return false;
}

bool ffPathExpandEnv(const char* in, FFstrbuf* out)
bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out)
{
bool result = false;

#if __has_include(<wordexp.h>) // https://github.com/termux/termux-packages/pull/7056

wordexp_t exp;
if(wordexp(in, &exp, WRDE_NOCMD) != 0)
return false;
Expand All @@ -123,6 +130,8 @@ bool ffPathExpandEnv(const char* in, FFstrbuf* out)

wordfree(&exp);

#endif

return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/detection/users/users_linux.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "fastfetch.h"
#include "users.h"

#if FF_HAVE_UTMPX_H
#if __has_include(<utmpx.h>)
#include <utmpx.h>
#else
//for Android compatibility
Expand Down

0 comments on commit e19242d

Please sign in to comment.