Skip to content

Commit 848be52

Browse files
committed
Reverted ancient console readin on STDIO files.
1 parent 49b8fe1 commit 848be52

File tree

1 file changed

+34
-66
lines changed

1 file changed

+34
-66
lines changed

library/termios/console_fdhookentry.c

Lines changed: 34 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -187,83 +187,51 @@ __termios_console_hook(struct _clib4 *__clib4, struct fd *fd, struct file_action
187187
assert(fam->fam_Data != NULL);
188188
assert(fam->fam_Size > 0);
189189

190-
if (FLAG_IS_CLEAR(fd->fd_Flags, FDF_STDIO)) {
191-
/* Attempt to fake everything needed in non-canonical mode. */
192-
if (FLAG_IS_SET(tios->c_lflag, ICANON)) {
193-
/* Canonical read = same as usual. Unless... */
194-
if (FLAG_IS_CLEAR(tios->c_lflag, ECHO)) {
195-
/* No-echo mode needs to be emulated. */
196-
result = LineEditor(file, fam->fam_Data, fam->fam_Size, tios);
197-
} else {
198-
result = Read(file, fam->fam_Data, fam->fam_Size);
199-
}
200-
} else if (fam->fam_Size > 0) {
201-
/* Non-canonical reads have timeouts and a minimum number of characters to read. */
202-
int i = 0;
203-
result = 0;
204-
205-
if (tios->c_cc[VMIN] > 0) {
206-
/* Reading the first character is not affected by the timeout unless VMIN==0. */
207-
i = Read(file, fam->fam_Data, 1);
208-
if (i == ERROR) {
209-
fam->fam_Error = EIO;
210-
goto out;
211-
}
190+
/* Attempt to fake everything needed in non-canonical mode. */
191+
if (FLAG_IS_SET(tios->c_lflag, ICANON)) {
192+
/* Canonical read = same as usual. Unless... */
193+
if (FLAG_IS_CLEAR(tios->c_lflag, ECHO)) {
194+
/* No-echo mode needs to be emulated. */
195+
result = LineEditor(file, fam->fam_Data, fam->fam_Size, tios);
196+
} else {
197+
result = Read(file, fam->fam_Data, fam->fam_Size);
198+
}
199+
} else if (fam->fam_Size > 0) {
200+
/* Non-canonical reads have timeouts and a minimum number of characters to read. */
201+
int i = 0;
202+
result = 0;
212203

213-
result = i;
204+
if (tios->c_cc[VMIN] > 0) {
205+
/* Reading the first character is not affected by the timeout unless VMIN==0. */
206+
i = Read(file, fam->fam_Data, 1);
207+
if (i == ERROR) {
208+
fam->fam_Error = EIO;
209+
goto out;
210+
}
214211

215-
while ((result < tios->c_cc[VMIN]) && (result < fam->fam_Size)) {
216-
if (tios->c_cc[VTIME] > 0) {
217-
if (WaitForChar(file, 100000 * tios->c_cc[VTIME]) == DOSFALSE) {
218-
break; /* No more characters available within alloted time. */
219-
}
220-
}
212+
result = i;
221213

222-
i = Read(file, &fam->fam_Data[result], 1);
223-
if (i <= 0) {
224-
break; /* Break out of this while loop only. */
214+
while ((result < tios->c_cc[VMIN]) && (result < fam->fam_Size)) {
215+
if (tios->c_cc[VTIME] > 0) {
216+
if (WaitForChar(file, 100000 * tios->c_cc[VTIME]) == DOSFALSE) {
217+
break; /* No more characters available within alloted time. */
225218
}
226-
227-
result += i;
228219
}
229-
} else {
230-
if (WaitForChar(file, 100000 * tios->c_cc[VTIME])) {
231-
result = Read(file, fam->fam_Data, fam->fam_Size);
232-
}
233-
}
234-
} else {
235-
result = 0; /* Reading zero characters will always succeed. */
236-
}
237-
} else {
238-
result = 0;
239-
/* Well.. this seems an hack to make ncurses works correctly
240-
* I don't know if there are other problems setting STDIO always
241-
* in RAW Mode but I suppose that we are ok since we are using
242-
* a termios hook
243-
*/
244-
SHOWVALUE(FLAG_IS_CLEAR(tios->c_lflag, ICANON));
245-
if (FLAG_IS_CLEAR(tios->c_lflag, ICANON)) {
246-
/* Set raw mode. */
247-
if (fam->fam_DOSMode == DOSFALSE) {
248-
SetMode(file, DOSTRUE);
249-
fam->fam_DOSMode = DOSTRUE;
250-
}
251-
if (tios->c_cc[VMIN] > 0 && tios->c_cc[VTIME] > 0) {
252-
if (WaitForChar(file, 100000 * tios->c_cc[VTIME])) {
253-
result = Read(file, fam->fam_Data, fam->fam_Size);
220+
221+
i = Read(file, &fam->fam_Data[result], 1);
222+
if (i <= 0) {
223+
break; /* Break out of this while loop only. */
254224
}
255-
} else {
256-
if (WaitForChar(file, 1))
257-
result = Read(file, fam->fam_Data, fam->fam_Size);
225+
226+
result += i;
258227
}
259228
} else {
260-
if (FLAG_IS_CLEAR(tios->c_lflag, ECHO)) {
261-
/* No-echo mode needs to be emulated. */
262-
result = LineEditor(file, fam->fam_Data, fam->fam_Size, tios);
263-
} else {
229+
if (WaitForChar(file, 100000 * tios->c_cc[VTIME])) {
264230
result = Read(file, fam->fam_Data, fam->fam_Size);
265231
}
266232
}
233+
} else {
234+
result = 0; /* Reading zero characters will always succeed. */
267235
}
268236

269237
if (result == ERROR) {

0 commit comments

Comments
 (0)