fix lines that terminate on EOF

This commit is contained in:
Vítor Santos Costa 2016-03-05 23:43:11 +00:00
parent 79d99a7768
commit bc914e9e91

View File

@ -62,12 +62,16 @@ static Int rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS) {
unsigned char *pt = buf;
do {
ch = st->stream_wgetc_for_read(sno);
if (ch < 127)
if (ch < 127) {
*pt++ = ch;
else
pt += get_utf8(pt, 4, &ch);
if (pt + 4 == buf + buf_sz)
break;
if (ch < 0) {
ch = '\n';
pt[-1] = '\n';
} else
pt += get_utf8(pt, 4, &ch);
if (pt + 4 == buf + buf_sz)
break;
}
} while (ch != '\n');
sz = pt - buf;
}
@ -150,10 +154,15 @@ static Int read_line_to_string(USES_REGS1) {
unsigned char *pt = buf;
do {
ch = st->stream_wgetc_for_read(sno);
if (ch < 127)
*pt++ = ch;
else
if (ch < 127) {
if (ch < 0) {
ch = '\n';
pt[-1] = '\n';
} else
*pt++ = ch;
} else {
pt += put_utf8(pt, ch);
}
if (pt + 4 == buf + buf_sz)
break;
} while (ch != '\n');