Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 284957 | Differences between
and this patch

Collapse All | Expand All

(-)klibc-1.5.orig/usr/dash/miscbltin.c (-3 / +39 lines)
Lines 46-51 Link Here
46
#include <ctype.h>
46
#include <ctype.h>
47
#include <stdint.h>
47
#include <stdint.h>
48
#include <time.h>		/* strtotimeval() */
48
#include <time.h>		/* strtotimeval() */
49
#include <termios.h>
49
50
50
#include "shell.h"
51
#include "shell.h"
51
#include "options.h"
52
#include "options.h"
Lines 83-88 Link Here
83
	int timeout;
84
	int timeout;
84
	int i;
85
	int i;
85
	fd_set set;
86
	fd_set set;
87
	int n_flag = 0;
88
	unsigned int nchars = 0;
89
	int silent = 0;
90
	struct termios tty, old_tty;
91
86
	struct timeval ts, t0, t1, to;
92
	struct timeval ts, t0, t1, to;
87
93
88
	ts.tv_sec = ts.tv_usec = 0;
94
	ts.tv_sec = ts.tv_usec = 0;
Lines 90-100 Link Here
90
	rflag = 0;
96
	rflag = 0;
91
	timeout = 0;
97
	timeout = 0;
92
	prompt = NULL;
98
	prompt = NULL;
93
	while ((i = nextopt("p:rt:")) != '\0') {
99
	while ((i = nextopt("p:rt:n:s")) != '\0') {
94
		switch(i) {
100
		switch(i) {
95
		case 'p':
101
		case 'p':
96
			prompt = optionarg;
102
			prompt = optionarg;
97
			break;
103
			break;
104
		case 'n':
105
			nchars = strtoul(optionarg, NULL, 10);
106
			n_flag = nchars; /* just a flag "nchars is nonzero" */
107
			break;
108
		case 's':
109
			silent = 1;
110
			break;
98
		case 't':
111
		case 't':
99
			p = strtotimeval(optionarg, &ts);
112
			p = strtotimeval(optionarg, &ts);
100
			if (*p || (!ts.tv_sec && !ts.tv_usec))
113
			if (*p || (!ts.tv_sec && !ts.tv_usec))
Lines 118-123 Link Here
118
		sh_error("arg count");
131
		sh_error("arg count");
119
	if ((ifs = bltinlookup("IFS")) == NULL)
132
	if ((ifs = bltinlookup("IFS")) == NULL)
120
		ifs = defifs;
133
		ifs = defifs;
134
	if (n_flag || silent) {
135
		if (tcgetattr(0, &tty) != 0) {
136
			/* Not a tty */
137
			n_flag = 0;
138
			silent = 0;
139
		} else {
140
			old_tty = tty;
141
			if (n_flag) {
142
				tty.c_lflag &= ~ICANON;
143
				tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
144
			}
145
			if (silent) {
146
				tty.c_lflag &= ~(ECHO | ECHOK | ECHONL);
147
			}
148
			tcsetattr(0, TCSANOW, &tty);
149
		}
150
	}
121
	status = 0;
151
	status = 0;
122
	startword = 1;
152
	startword = 1;
123
	backslash = 0;
153
	backslash = 0;
Lines 133-145 Link Here
133
		ts.tv_sec += t0.tv_sec;
163
		ts.tv_sec += t0.tv_sec;
134
	}
164
	}
135
	STARTSTACKSTR(p);
165
	STARTSTACKSTR(p);
136
	for (;;) {
166
	do {
137
		if (timeout) {
167
		if (timeout) {
138
			gettimeofday(&t1, NULL);
168
			gettimeofday(&t1, NULL);
139
			if (t1.tv_sec > ts.tv_sec ||
169
			if (t1.tv_sec > ts.tv_sec ||
140
			    (t1.tv_sec == ts.tv_sec &&
170
			    (t1.tv_sec == ts.tv_sec &&
141
			     t1.tv_usec >= ts.tv_usec)) {
171
			     t1.tv_usec >= ts.tv_usec)) {
142
				status = 1;
172
				status = 1;
173
				if (n_flag)
174
					tcsetattr(0, TCSANOW, &old_tty);
143
				break;	/* Timeout! */
175
				break;	/* Timeout! */
144
			}
176
			}
145
177
Lines 156-161 Link Here
156
			FD_SET(0, &set);
188
			FD_SET(0, &set);
157
			if (select(1, &set, NULL, NULL, &to) != 1) {
189
			if (select(1, &set, NULL, NULL, &to) != 1) {
158
				status = 1;
190
				status = 1;
191
				if (n_flag)
192
					tcsetattr(0, TCSANOW, &old_tty);
159
				break; /* Timeout! */
193
				break; /* Timeout! */
160
			}
194
			}
161
		}
195
		}
Lines 191-197 Link Here
191
put:
225
put:
192
			STPUTC(c, p);
226
			STPUTC(c, p);
193
		}
227
		}
194
	}
228
	} while (!n_flag || --nchars);
229
	if (n_flag || silent)
230
		tcsetattr(0, TCSANOW, &old_tty);
195
	STACKSTRNUL(p);
231
	STACKSTRNUL(p);
196
	/* Remove trailing blanks */
232
	/* Remove trailing blanks */
197
	while ((char *)stackblock() <= --p && strchr(ifs, *p) != NULL)
233
	while ((char *)stackblock() <= --p && strchr(ifs, *p) != NULL)

Return to bug 284957