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-07 01:07:52.000000000 +0200
3 +++ ./usr/include/pwd.h 2017-06-18 01:54:51.654897945 +0200
5 struct passwd* getpwent(void) __INTRODUCED_IN(26);
7 void setpwent(void) __INTRODUCED_IN(26);
8 -void endpwent(void) __INTRODUCED_IN(26);
9 #endif /* __ANDROID_API__ >= 26 */
13 int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**) __INTRODUCED_IN(12);
14 #endif /* __ANDROID_API__ >= 12 */
16 +static void android_setup_pwd(struct passwd* pw) {
17 + static char realpath_buffer[4096/*PATH_MAX*/];
18 + char* result = realpath("@TERMUX_HOME@/.termux/shell", realpath_buffer);
19 + if (result == NULL || access(realpath_buffer, X_OK) == -1) {
20 + char const* bash_path = "@TERMUX_PREFIX@/bin/bash";
21 + if (access(bash_path, X_OK) != -1) pw->pw_shell = (char*) bash_path;
22 + else pw->pw_shell = "@TERMUX_PREFIX@/bin/sh";
24 + pw->pw_shell = realpath_buffer;
26 + pw->pw_dir = "@TERMUX_HOME@";
27 + pw->pw_passwd = "*";
29 + pw->pw_gecos = ""; /* Avoid NULL field. */
33 +static struct passwd* android_polyfill_getpwuid(uid_t t) {
34 + struct passwd* pw = getpwuid(t);
35 + if (pw == NULL) return NULL;
36 + android_setup_pwd(pw);
40 +static struct passwd* android_polyfill_getpwnam(const char* name) {
41 + struct passwd* pw = getpwnam(name);
42 + if (pw == NULL) return NULL;
43 + android_setup_pwd(pw);
47 +static int android_polyfill_getpwuid_r(uid_t uid,
51 + struct passwd **result) {
52 + int ret = getpwuid_r(uid, pwd, buffer, bufsize, result);
53 + if (ret != 0) return ret;
54 + android_setup_pwd(pwd);
58 +#define getpwnam android_polyfill_getpwnam
59 +#define getpwuid android_polyfill_getpwuid
60 +#define getpwuid_r android_polyfill_getpwuid_r
61 +static void endpwent(void) { /* Do nothing. */ }