1 diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/pwd.h ./usr/include/pwd.h
2 --- /home/fornwall/lib/android-ndk/sysroot/usr/include/pwd.h 2017-06-20 17:41:56.000000000 +0200
3 +++ ./usr/include/pwd.h 2017-06-26 11:45:26.036064547 +0200
8 +#include <stdlib.h> /* For realpath() */
14 struct passwd* getpwent(void) __INTRODUCED_IN(26);
16 void setpwent(void) __INTRODUCED_IN(26);
17 -void endpwent(void) __INTRODUCED_IN(26);
18 #endif /* __ANDROID_API__ >= 26 */
22 int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**) __INTRODUCED_IN(12);
23 #endif /* __ANDROID_API__ >= 12 */
25 +int access(const char* __path, int __mode);
27 +static void android_setup_pwd(struct passwd* pw) {
28 + static char realpath_buffer[4096/*PATH_MAX*/];
29 + char* result = realpath("/data/data/com.termux/files/home/.termux/shell", realpath_buffer);
30 + if (result == NULL || access(realpath_buffer, /*X_OK*/1) == -1) {
31 + char const* bash_path = "/data/data/com.termux/files/usr/bin/bash";
32 + if (access(bash_path, /*X_OK*/1) != -1) pw->pw_shell = (char*) bash_path;
33 + else pw->pw_shell = "/data/data/com.termux/files/usr/bin/sh";
35 + pw->pw_shell = realpath_buffer;
37 + pw->pw_dir = "/data/data/com.termux/files/home";
38 + pw->pw_passwd = "*";
40 + pw->pw_gecos = ""; /* Avoid NULL field. */
44 +static struct passwd* android_polyfill_getpwuid(uid_t t) {
45 + struct passwd* pw = getpwuid(t);
46 + if (pw == NULL) return NULL;
47 + android_setup_pwd(pw);
51 +static struct passwd* android_polyfill_getpwnam(const char* name) {
52 + struct passwd* pw = getpwnam(name);
53 + if (pw == NULL) return NULL;
54 + android_setup_pwd(pw);
58 +static int android_polyfill_getpwuid_r(uid_t uid,
62 + struct passwd **result) {
63 + int ret = getpwuid_r(uid, pwd, buffer, bufsize, result);
64 + if (ret != 0) return ret;
65 + android_setup_pwd(pwd);
69 +#define getpwnam android_polyfill_getpwnam
70 +#define getpwuid android_polyfill_getpwuid
71 +#define getpwuid_r android_polyfill_getpwuid_r
72 +static void endpwent(void) { /* Do nothing. */ }