don't restart on EINTR, instead return NULL immediately. From Anon Ymous

This commit is contained in:
christos 2009-02-15 21:24:13 +00:00
parent b16648eaeb
commit 6ed9cd5e69
2 changed files with 26 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: el.h,v 1.17 2006/12/15 22:13:33 christos Exp $ */
/* $NetBSD: el.h,v 1.18 2009/02/15 21:24:13 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -115,6 +115,7 @@ struct editline {
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
int el_flags; /* Various flags. */
int el_errno; /* Local copy of errno */
coord_t el_cursor; /* Cursor location */
char **el_display; /* Real screen image = what is there */
char **el_vdisplay; /* Virtual screen image = what we see */

View File

@ -1,4 +1,4 @@
/* $NetBSD: read.c,v 1.43 2009/02/05 19:15:44 christos Exp $ */
/* $NetBSD: read.c,v 1.44 2009/02/15 21:24:13 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: read.c,v 1.43 2009/02/05 19:15:44 christos Exp $");
__RCSID("$NetBSD: read.c,v 1.44 2009/02/15 21:24:13 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -51,7 +51,7 @@ __RCSID("$NetBSD: read.c,v 1.43 2009/02/05 19:15:44 christos Exp $");
#include <stdlib.h>
#include "el.h"
#define OKCMD -1
#define OKCMD -1 /* must be -1! */
private int read__fixio(int, int);
private int read_preread(EditLine *);
@ -172,7 +172,7 @@ read__fixio(int fd __attribute__((__unused__)), int e)
return (e ? 0 : -1);
case EINTR:
return (0);
return (-1);
default:
return (-1);
@ -237,9 +237,12 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
el_action_t cmd;
int num;
el->el_errno = 0;
do {
if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
if ((num = el_getc(el, ch)) != 1) { /* if EOF or error */
el->el_errno = errno;
return (num);
}
#ifdef KANJI
if ((*ch & 0200)) {
@ -412,7 +415,7 @@ el_gets(EditLine *el, int *nread)
char *cp = el->el_line.buffer;
size_t idx;
while ((*el->el_read.read_char)(el, cp) == 1) {
while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space for next character */
if (cp + 1 >= el->el_line.limit) {
idx = (cp - el->el_line.buffer);
@ -426,12 +429,14 @@ el_gets(EditLine *el, int *nread)
if (cp[-1] == '\r' || cp[-1] == '\n')
break;
}
if (num == -1 && errno == EINTR)
cp = el->el_line.buffer;
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
if (nread)
*nread = el->el_line.cursor - el->el_line.buffer;
return (el->el_line.buffer);
return (*nread ? el->el_line.buffer : NULL);
}
@ -456,6 +461,7 @@ el_gets(EditLine *el, int *nread)
if (el->el_flags & EDIT_DISABLED) {
char *cp;
size_t idx;
if ((el->el_flags & UNBUFFERED) == 0)
cp = el->el_line.buffer;
else
@ -463,7 +469,7 @@ el_gets(EditLine *el, int *nread)
term__flush(el);
while ((*el->el_read.read_char)(el, cp) == 1) {
while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space next character */
if (cp + 1 >= el->el_line.limit) {
idx = (cp - el->el_line.buffer);
@ -480,12 +486,14 @@ el_gets(EditLine *el, int *nread)
if (crlf)
break;
}
if (num == -1 && errno == EINTR)
cp = el->el_line.buffer;
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
if (nread)
*nread = el->el_line.cursor - el->el_line.buffer;
return (el->el_line.buffer);
return (*nread ? el->el_line.buffer : NULL);
}
for (num = OKCMD; num == OKCMD;) { /* while still editing this
@ -501,6 +509,13 @@ el_gets(EditLine *el, int *nread)
#endif /* DEBUG_READ */
break;
}
if (el->el_errno == EINTR) {
el->el_line.buffer[0] = '\0';
el->el_line.lastchar =
el->el_line.cursor = el->el_line.buffer;
num = 0;
break;
}
if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) { /* BUG CHECK command */
#ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile,