summaryrefslogtreecommitdiffstats
path: root/meta-initramfs/recipes-devtools/klibc/klibc-1.5.26+2.0/dash_readopt.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-initramfs/recipes-devtools/klibc/klibc-1.5.26+2.0/dash_readopt.patch')
-rw-r--r--meta-initramfs/recipes-devtools/klibc/klibc-1.5.26+2.0/dash_readopt.patch111
1 files changed, 111 insertions, 0 deletions
diff --git a/meta-initramfs/recipes-devtools/klibc/klibc-1.5.26+2.0/dash_readopt.patch b/meta-initramfs/recipes-devtools/klibc/klibc-1.5.26+2.0/dash_readopt.patch
new file mode 100644
index 000000000..3be1be04f
--- /dev/null
+++ b/meta-initramfs/recipes-devtools/klibc/klibc-1.5.26+2.0/dash_readopt.patch
@@ -0,0 +1,111 @@
1Patch was imported from the OpenEmbedded git server
2(git://git.openembedded.org/openembedded)
3as of commit id ad67a97e8fbfb03a68088a6ca6ad87b086c88094
4Signed-off-by: Thomas Kunze <thommycheck@gmx.de>
5Minor adjustments tracking upstream changes
6Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
7
8diff -uNr klibc-1.5.22.orig//usr/dash/miscbltin.c klibc-1.5.22/usr/dash/miscbltin.c
9--- klibc-1.5.22.orig//usr/dash/miscbltin.c 2011-06-11 02:08:49.000000000 +0200
10+++ klibc-1.5.22/usr/dash/miscbltin.c 2011-06-11 13:55:32.000000000 +0200
11@@ -46,6 +46,7 @@
12 #include <ctype.h>
13 #include <inttypes.h>
14 #include <time.h> /* strtotimeval() */
15+#include <termios.h>
16
17 #include "shell.h"
18 #include "options.h"
19@@ -149,6 +150,11 @@
20 int timeout;
21 int i;
22 fd_set set;
23+ int n_flag = 0;
24+ unsigned int nchars = 0;
25+ int silent = 0;
26+ struct termios tty, old_tty;
27+
28 struct timeval ts, t0, t1, to;
29
30 ts.tv_sec = ts.tv_usec = 0;
31@@ -156,11 +162,18 @@
32 rflag = 0;
33 timeout = 0;
34 prompt = NULL;
35- while ((i = nextopt("p:rt:")) != '\0') {
36+ while ((i = nextopt("p:rt:n:s")) != '\0') {
37 switch(i) {
38 case 'p':
39 prompt = optionarg;
40 break;
41+ case 'n':
42+ nchars = strtoul(optionarg, NULL, 10);
43+ n_flag = nchars; /* just a flag "nchars is nonzero" */
44+ break;
45+ case 's':
46+ silent = 1;
47+ break;
48 case 't':
49 p = strtotimeval(optionarg, &ts);
50 if (*p || (!ts.tv_sec && !ts.tv_usec))
51@@ -182,6 +197,24 @@
52 }
53 if (*(ap = argptr) == NULL)
54 sh_error("arg count");
55+ if (n_flag || silent) {
56+ if (tcgetattr(0, &tty) != 0) {
57+ /* Not a tty */
58+ n_flag = 0;
59+ silent = 0;
60+ } else {
61+ old_tty = tty;
62+ if (n_flag) {
63+ tty.c_lflag &= ~ICANON;
64+ tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
65+ }
66+ if (silent) {
67+ tty.c_lflag &= ~(ECHO | ECHOK | ECHONL);
68+ }
69+ tcsetattr(0, TCSANOW, &tty);
70+ }
71+ }
72+
73
74 status = 0;
75 if (timeout) {
76@@ -200,12 +231,14 @@
77 goto start;
78
79- for (;;) {
80+ do {
81 if (timeout) {
82 gettimeofday(&t1, NULL);
83 if (t1.tv_sec > ts.tv_sec ||
84 (t1.tv_sec == ts.tv_sec &&
85 t1.tv_usec >= ts.tv_usec)) {
86 status = 1;
87+ if (n_flag)
88+ tcsetattr(0, TCSANOW, &old_tty);
89 break; /* Timeout! */
90 }
91
92@@ -222,6 +255,8 @@
93 FD_SET(0, &set);
94 if (select(1, &set, NULL, NULL, &to) != 1) {
95 status = 1;
96+ if (n_flag)
97+ tcsetattr(0, TCSANOW, &old_tty);
98 break; /* Timeout! */
99 }
100 }
101@@ -263,6 +298,9 @@
102 newloc = startloc - 1;
103 }
104- }
105+ } while (!n_flag || --nchars);
106+ if (n_flag || silent)
107+ tcsetattr(0, TCSANOW, &old_tty);
108+
109 out:
110 recordregion(startloc, p - (char *)stackblock(), 0);
111 STACKSTRNUL(p);