libxml2: Update from 2.9.2 to 2.9.3
[termux-packages] / ndk_patches / pwd.patch
CommitLineData
b57fc0bb
FF
1diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h ./usr/include/pwd.h
2--- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h 2014-10-14 22:53:49.000000000 -0400
3+++ ./usr/include/pwd.h 2015-07-15 09:42:32.974621965 -0400
6d5e9115 4@@ -65,6 +65,10 @@
b57fc0bb
FF
5 #include <sys/cdefs.h>
6 #include <sys/types.h>
7
6d5e9115 8+/* For access() and realpath(): */
b57fc0bb 9+#include <unistd.h>
6d5e9115 10+#include <stdlib.h>
b57fc0bb
FF
11+
12 #define _PATH_PASSWD "/etc/passwd"
13 #define _PATH_MASTERPASSWD "/etc/master.passwd"
14 #define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
6d5e9115 15@@ -119,6 +122,36 @@
b57fc0bb
FF
16 int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
17 int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
18
59f0d218 19+static void android_setup_pwd(struct passwd* pw) {
b57fc0bb
FF
20+ static char realpath_buffer[4096/*PATH_MAX*/];
21+ char* result = realpath("@TERMUX_HOME@/.termux/shell", realpath_buffer);
22+ if (result == NULL || access(realpath_buffer, X_OK) == -1) {
02b55df6 23+ char const* bash_path = "@TERMUX_PREFIX@/bin/bash";
34165430 24+ if (access(bash_path, X_OK) != -1) pw->pw_shell = (char*) bash_path;
02b55df6 25+ else pw->pw_shell = "@TERMUX_PREFIX@/bin/ash";
59f0d218 26+ } else {
394bbb64 27+ pw->pw_shell = strcmp(realpath_buffer, "@TERMUX_PREFIX@/bin/busybox") == 0 ? (char*)"@TERMUX_PREFIX@/bin/ash" : realpath_buffer;
59f0d218 28+ }
59f0d218
FF
29+ pw->pw_dir = "@TERMUX_HOME@";
30+ pw->pw_passwd = "*";
31+}
32+
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);
37+ return pw;
38+}
39+
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);
44+ return pw;
45+}
46+
47+#define getpwnam android_polyfill_getpwnam
48+#define getpwuid android_polyfill_getpwuid
49 void endpwent(void);
b57fc0bb
FF
50 struct passwd* getpwent(void);
51 int setpwent(void);