0
0
mirror of https://github.com/termux/termux-packages.git synced 2024-11-23 14:56:16 +00:00
termux-packages/ndk-patches/23c/unistd.h.patch
Henrik Grimler e7f4ad8b6d
scripts: rename termux_step_setup_toolchain to indicate NDK version
And keep ndk-patches in 23c/ subdirectory.  Run
termux_step_setup_toolchain_23c only if TERMUX_NDK_VERSION equals 23c.

This is a step towards having the possibility to use different NDK
versions.  Using a different NDK version than the one termux
officially supports should *really* not be done except for
testing/debug/development reasons, or if it is strictly necessary to
be able to compile a program (for example for packages that need a
fortran compiler, which at the moment is only supported with old
gcc-using NDKs).
2022-08-13 12:19:59 +02:00

78 lines
2.2 KiB
Diff

--- ./usr/include/unistd.h.orig 2021-08-16 11:52:08.095542840 +0200
+++ ./usr/include/unistd.h 2021-08-16 11:52:08.565542673 +0200
@@ -375,6 +375,74 @@
#undef _UNISTD_H_
#endif
+#if !defined GETPASS_H && !defined getpass && !defined HAVE_GETPASS && !defined HAS_GETPASS && !defined NO_INLINE_GETPASS
+#define GETPASS_H 1
+#define HAVE_GETPASS 1
+#define HAS_GETPASS 1
+#define PASSWORDLEN 512
+
+static __inline__ char* getpass(const char* prompt) {
+ // termios struct as in asm-generic/termbits.h
+ struct _termios {
+ unsigned int c_iflag; /* input mode flags */
+ unsigned int c_oflag; /* output mode flags */
+ unsigned int c_cflag; /* control mode flags */
+ unsigned int c_lflag; /* local mode flags */
+ unsigned char c_line; /* line discipline */
+ unsigned char c_cc[19/* NCCS */]; /* control characters */
+ };
+
+ struct _termios term_old, term_new;
+ static char password[513] = { 0 }; /* 512 1-byte charactes and '0' */
+ int len = 0, tty_changed = 0;
+
+ // print prompt
+ while (*prompt) {
+ write(1, prompt, 1);
+ prompt++;
+ }
+
+ // try to disable echoing on terminal
+ if (ioctl(0, 0x5401 /* TCGETS */, &term_old) == 0) {
+ term_new = term_old;
+ term_new.c_lflag &= ~0000010;/* ~ECHO */
+
+ if (ioctl(0, 0x5402+0 /* TCSETS+TCSANOW */, &term_new) == 0) {
+ tty_changed = 1;
+ } else {
+ tty_changed = 0;
+ }
+ }
+
+ // read password
+ char chr;
+ while (read(0, &chr, sizeof(char)) > 0) {
+ if (chr == '\r' || chr == '\n' || chr == 0) {
+ break;
+ }
+
+ if (len == sizeof(password)-1) {
+ // we should consume all entered characters even
+ // if maximal input length reached
+ continue;
+ } else {
+ password[len++] = chr;
+ }
+ }
+ password[len] = 0;
+
+ // restore terminal to previous state if needed
+ if (tty_changed) {
+ ioctl(0, 0x5402+0 /* TCSETS+TCSANOW */, &term_old);
+ }
+
+ // force new line
+ write(1, "\n", 1);
+
+ return password;
+}
+#endif
+
__END_DECLS
#include <android/legacy_unistd_inlines.h>