Minix editline v0.2.1

=====================

Fix Debian batch mode reader, read_redirected(), which is activated
when input comes from a file rather than a tty.  

The implementation of read_redirected() did not support lines longer
than 64 chars.  It tried to realloc(), but goofed up and instead
truncated all the first 64 chars.  The result was that each read
line only contained the reminder of a a division with 64... :-)
This commit is contained in:
Joachim Nilsson
2008-06-09 22:55:13 +02:00
parent 64cc1b5325
commit b935808b7d
3 changed files with 22 additions and 15 deletions

View File

@@ -988,18 +988,24 @@ hist_add(p)
}
STATIC char *
read_redirected()
read_redirected(void)
{
int size;
int size = MEM_INC;
char *p;
char *line;
char *end;
for (size = MEM_INC, p = line = NEW(char, size), end = p + size; ; p++) {
p = line = NEW(char, size);
end = p + size;
while (1) {
if (p == end) {
int oldpos = end - line;
size += MEM_INC;
p = line = realloc(line, size);
p = RENEW(line, char, size);
end = p + size;
p += oldpos; /* Continue where we left off... */
}
if (read(0, p, 1) <= 0) {
/* Ignore "incomplete" lines at EOF, just like we do for a tty. */
@@ -1008,6 +1014,7 @@ read_redirected()
}
if (*p == '\n')
break;
p++;
}
*p = '\0';
return line;