From 2f2b394d721fcb67b3dedd047f18339ed8d7de94 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 26 Oct 2016 11:25:23 +0200 Subject: [PATCH] fs/StandardDirectory: no /etc/passwd lookups on Android This doesn't make sense on Android; there is no home directory for users. --- src/fs/StandardDirectory.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx index 66f4c74bf..0bd2f917a 100644 --- a/src/fs/StandardDirectory.cxx +++ b/src/fs/StandardDirectory.cxx @@ -54,7 +54,7 @@ #include "Main.hxx" #endif -#ifndef WIN32 +#if !defined(WIN32) && !defined(ANDROID) class PasswdEntry { #if defined(HAVE_GETPWNAM_R) || defined(HAVE_GETPWUID_R) @@ -91,6 +91,7 @@ public: }; #endif +#ifndef ANDROID static inline bool IsValidPathString(PathTraitsFS::const_pointer_type path) { @@ -111,6 +112,7 @@ SafePathFromFS(PathTraitsFS::const_pointer_type dir) return AllocatedPath::FromFS(dir); return AllocatedPath::Null(); } +#endif #ifdef WIN32 static AllocatedPath GetStandardDir(int folder_id) @@ -310,21 +312,27 @@ AllocatedPath GetAppBaseDir() AllocatedPath GetHomeDir() { +#ifndef ANDROID auto home = getenv("HOME"); if (IsValidPathString(home) && IsValidDir(home)) return AllocatedPath::FromFS(home); PasswdEntry pw; if (pw.ReadByUid(getuid())) return SafePathFromFS(pw->pw_dir); +#endif return AllocatedPath::Null(); } AllocatedPath GetHomeDir(const char *user_name) { +#ifdef ANDROID + (void)user_name; +#else assert(user_name != nullptr); PasswdEntry pw; if (pw.ReadByName(user_name)) return SafePathFromFS(pw->pw_dir); +#endif return AllocatedPath::Null(); }