termux-packages/packages/unrar/getpass.patch

54 lines
1.3 KiB
Diff

diff -uNr unrar/consio.cpp unrar.mod/consio.cpp
--- unrar/consio.cpp 2018-06-24 18:10:30.000000000 +0300
+++ unrar.mod/consio.cpp 2018-07-03 14:07:07.362069977 +0300
@@ -1,6 +1,10 @@
#include "rar.hpp"
#include "log.cpp"
+// For getpass()
+#include <termios.h>
+#include <readline/readline.h>
+
static MESSAGE_TYPE MsgStream=MSG_STDOUT;
static RAR_CHARSET RedirectCharset=RCH_DEFAULT;
@@ -62,6 +66,38 @@
#ifndef SILENT
+#ifdef __ANDROID__
+static char* getpass(const char *prompt) {
+ struct termios term_old, term_new;
+
+ /* Turn echoing off and fail if we can't. */
+ if (tcgetattr(0, &term_old) != 0) {
+ fprintf(stderr, "%s(): tcgetattr failed.\n", __func__);
+ return NULL;
+ }
+
+ term_new = term_old;
+ term_new.c_lflag &= ~ECHO;
+
+ if (tcsetattr(0, TCSANOW, &term_new) != 0) {
+ fprintf(stderr, "%s(): tcsetattr failed.\n", __func__);
+ return NULL;
+ }
+
+ /* Read the password. */
+ char *password = readline(prompt);
+
+ /* prevent segfault when failed to read password */
+ if (!password) {
+ password="";
+ }
+
+ /* Restore terminal. */
+ (void) tcsetattr(0, TCSANOW, &term_old);
+
+ return password;
+}
+#endif
static void cvt_wprintf(FILE *dest,const wchar *fmt,va_list arglist)
{
// This buffer is for format string only, not for entire output,