vm: C I/O streams became unusable after a single EOF (reported by John Benediktsson)

db4
Slava Pestov 2010-08-22 20:56:29 -07:00
parent 2abda04743
commit f1bec796bb
1 changed files with 7 additions and 0 deletions

View File

@ -190,7 +190,10 @@ void factor_vm::primitive_fgetc()
int c = safe_fgetc(file);
if(c == EOF && feof(file))
{
clearerr(file);
ctx->push(false_object);
}
else
ctx->push(tag_fixnum(c));
}
@ -210,11 +213,15 @@ void factor_vm::primitive_fread()
size_t c = safe_fread(buf.untagged() + 1,1,size,file);
if(c == 0)
{
clearerr(file);
ctx->push(false_object);
}
else
{
if(feof(file))
{
clearerr(file);
byte_array *new_buf = allot_byte_array(c);
memcpy(new_buf->data<char>(), buf->data<char>(),c);
buf = new_buf;