From fe8727fb71848e0508a9b1a2ea35ac9080fd42c8 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Sun, 16 Oct 2016 02:20:53 +0200 Subject: [PATCH] Fix building on Android by avoiding getpwent() (#3441) * Fix building on Android by avoiding getpwent() if missing with autoconf check The getpwent() function does not link when building for Android, and user names on that platform are not interesting anyway. --- configure.ac | 1 + src/complete.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/configure.ac b/configure.ac index 0e5e13b56..f6558112e 100644 --- a/configure.ac +++ b/configure.ac @@ -302,6 +302,7 @@ AC_CHECK_FUNCS( futimes ) AC_CHECK_FUNCS( wcslcpy lrand48_r killpg ) AC_CHECK_FUNCS( backtrace_symbols getifaddrs ) AC_CHECK_FUNCS( futimens clock_gettime ) +AC_CHECK_FUNCS( getpwent ) AC_CHECK_DECL( [mkostemp], [ AC_CHECK_FUNCS([mkostemp]) ] ) diff --git a/src/complete.cpp b/src/complete.cpp index 5ecf80eb9..9491c58b8 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -1187,6 +1187,13 @@ bool completer_t::try_complete_variable(const wcstring &str) { /// /// \return 0 if unable to complete, 1 otherwise bool completer_t::try_complete_user(const wcstring &str) { +#ifndef HAVE_GETPWENT + // The getpwent() function does not exist on Android. A Linux user on Android isn't + // really a user - each installed app gets an UID assigned. Listing all UID:s is not + // possible without root access, and doing a ~USER type expansion does not make sense + // since every app is sandboxed and can't access eachother. + return false; +#else const wchar_t *cmd = str.c_str(); const wchar_t *first_char = cmd; int res = 0; @@ -1233,6 +1240,7 @@ bool completer_t::try_complete_user(const wcstring &str) { } return res; +#endif } void complete(const wcstring &cmd_with_subcmds, std::vector *out_comps,