libhdf5: limit to aarch64 for now
[termux-packages] / ndk-patches / pwd.h.patch
CommitLineData
29bf3001 1diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/pwd.h ./usr/include/pwd.h
6e4505aa
FF
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
6e4505aa 4@@ -89,7 +91,6 @@
29bf3001
FF
5 struct passwd* getpwent(void) __INTRODUCED_IN(26);
6
7 void setpwent(void) __INTRODUCED_IN(26);
8-void endpwent(void) __INTRODUCED_IN(26);
9 #endif /* __ANDROID_API__ >= 26 */
10
11
8ebeeaa3 12@@ -99,6 +100,51 @@
29bf3001
FF
13 int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**) __INTRODUCED_IN(12);
14 #endif /* __ANDROID_API__ >= 12 */
15
6dad78cb
FF
16+int access(const char* __path, int __mode);
17+
29bf3001 18+static void android_setup_pwd(struct passwd* pw) {
8ebeeaa3
FF
19+ char const* result = "@TERMUX_PREFIX@/bin/login";
20+ if (result == NULL || access(result, /*X_OK*/1) == -1) {
21+ pw->pw_shell = "@TERMUX_PREFIX@/bin/bash";
29bf3001 22+ } else {
b461954b 23+ pw->pw_shell = (char*) result;
29bf3001 24+ }
8ebeeaa3 25+ pw->pw_dir = "@TERMUX_HOME@";
29bf3001
FF
26+ pw->pw_passwd = "*";
27+#ifdef __LP64__
28+ pw->pw_gecos = ""; /* Avoid NULL field. */
29+#endif
30+}
31+
32+static struct passwd* android_polyfill_getpwuid(uid_t t) {
33+ struct passwd* pw = getpwuid(t);
34+ if (pw == NULL) return NULL;
35+ android_setup_pwd(pw);
36+ return pw;
37+}
38+
39+static struct passwd* android_polyfill_getpwnam(const char* name) {
40+ struct passwd* pw = getpwnam(name);
41+ if (pw == NULL) return NULL;
42+ android_setup_pwd(pw);
43+ return pw;
44+}
45+
46+static int android_polyfill_getpwuid_r(uid_t uid,
47+ struct passwd *pwd,
48+ char *buffer,
49+ size_t bufsize,
50+ struct passwd **result) {
51+ int ret = getpwuid_r(uid, pwd, buffer, bufsize, result);
52+ if (ret != 0) return ret;
53+ android_setup_pwd(pwd);
54+ return 0;
55+}
56+
57+#define getpwnam android_polyfill_getpwnam
58+#define getpwuid android_polyfill_getpwuid
59+#define getpwuid_r android_polyfill_getpwuid_r
60+static void endpwent(void) { /* Do nothing. */ }
61
62 __END_DECLS
63