summaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-02-02 00:23:55 +0100
committerGravatar Nikias Bassen2019-02-02 00:23:55 +0100
commit519af01f7dcb448b59ca13bdc1a1b060484f41ec (patch)
tree3fc370ff01e8daefaa222884848e3d93142cd3db /src/common.c
parent65572cab6baf92cbe4d43fcb0c7a44bc87d95b85 (diff)
downloadidevicerestore-519af01f7dcb448b59ca13bdc1a1b060484f41ec.tar.gz
idevicerestore-519af01f7dcb448b59ca13bdc1a1b060484f41ec.tar.bz2
Use ipsw.me API to allow selection and download of any signed firmware version when using --latest
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c
index 59e37a5..c7064d9 100644
--- a/src/common.c
+++ b/src/common.c
@@ -34,9 +34,11 @@
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <ctype.h>
#ifdef WIN32
#include <windows.h>
+#include <conio.h>
#ifndef _O_EXCL
#define _O_EXCL 0x0400
#endif
@@ -46,6 +48,7 @@
#else
#include <sys/time.h>
#include <pthread.h>
+#include <termios.h>
#endif
#include "common.h"
@@ -481,3 +484,45 @@ char* strsep(char** strp, const char* delim)
return s;
}
#endif
+
+#ifdef WIN32
+#define BS_CC '\b'
+#define my_getch getch
+#else
+#define BS_CC 0x7f
+static int my_getch(void)
+{
+ struct termios oldt, newt;
+ int ch;
+ tcgetattr(STDIN_FILENO, &oldt);
+ newt = oldt;
+ newt.c_lflag &= ~(ICANON | ECHO);
+ tcsetattr(STDIN_FILENO, TCSANOW, &newt);
+ ch = getchar();
+ tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
+ return ch;
+}
+#endif
+
+void get_user_input(char *buf, int maxlen, int secure)
+{
+ int len = 0;
+ int c;
+
+ while ((c = my_getch())) {
+ if ((c == '\r') || (c == '\n')) {
+ break;
+ } else if (isprint(c)) {
+ if (len < maxlen-1)
+ buf[len++] = c;
+ fputc((secure) ? '*' : c, stdout);
+ } else if (c == BS_CC) {
+ if (len > 0) {
+ fputs("\b \b", stdout);
+ len--;
+ }
+ }
+ }
+ fputs("\n", stdout);
+ buf[len] = 0;
+}