1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 05:50:26 +02:00

* fports.c (scm_fgets): Return if the last char in a chunk is

newline.  When fgets returns a string whose length is `size-1', it
	is ambiguous whether a whole line was retrieved, so we must check
	explicitly whether a line terminator is present.
This commit is contained in:
Tim Pierce 1997-12-04 19:05:05 +00:00
parent 1ea4704837
commit 8122b543c1
2 changed files with 25 additions and 15 deletions

View file

@ -1,3 +1,10 @@
1997-12-04 Tim Pierce <twp@ppp39.Nantucket.net>
* fports.c (scm_fgets): Return if the last char in a chunk is
newline. When fgets returns a string whose length is `size-1', it
is ambiguous whether a whole line was retrieved, so we must check
explicitly whether a line terminator is present.
1997-12-04 Mikael Djurfeldt <mdj@mdj.nada.kth.se>
* print.h (SCM_COERCE_OUTPORT): Check that the object is a pair

View file

@ -326,23 +326,26 @@ scm_fgets (port)
}
}
while (1) {
p = buf + i;
if (fgets (p, limit - i, f) == NULL) {
if (i)
while (1)
{
int chunk_size = limit - i;
p = buf + i;
if (fgets (p, chunk_size, f) == NULL) {
if (i)
return buf;
free (buf);
return NULL;
}
if (strlen(p) < chunk_size - 1 || buf[limit-2] == '\n')
return buf;
free (buf);
return NULL;
buf = (char *) realloc (buf, sizeof(char) * limit * 2);
i = limit - 1;
limit *= 2;
}
if (strlen(p) < limit - i - 1)
return buf;
buf = (char *) realloc (buf, sizeof(char) * limit * 2);
i = limit - 1;
limit *= 2;
}
}
#ifdef vms