vm: C I/O streams became unusable after a single EOF (reported by John Benediktsson)
parent
2abda04743
commit
f1bec796bb
|
@ -190,7 +190,10 @@ void factor_vm::primitive_fgetc()
|
||||||
|
|
||||||
int c = safe_fgetc(file);
|
int c = safe_fgetc(file);
|
||||||
if(c == EOF && feof(file))
|
if(c == EOF && feof(file))
|
||||||
|
{
|
||||||
|
clearerr(file);
|
||||||
ctx->push(false_object);
|
ctx->push(false_object);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ctx->push(tag_fixnum(c));
|
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);
|
size_t c = safe_fread(buf.untagged() + 1,1,size,file);
|
||||||
if(c == 0)
|
if(c == 0)
|
||||||
|
{
|
||||||
|
clearerr(file);
|
||||||
ctx->push(false_object);
|
ctx->push(false_object);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(feof(file))
|
if(feof(file))
|
||||||
{
|
{
|
||||||
|
clearerr(file);
|
||||||
byte_array *new_buf = allot_byte_array(c);
|
byte_array *new_buf = allot_byte_array(c);
|
||||||
memcpy(new_buf->data<char>(), buf->data<char>(),c);
|
memcpy(new_buf->data<char>(), buf->data<char>(),c);
|
||||||
buf = new_buf;
|
buf = new_buf;
|
||||||
|
|
Loading…
Reference in New Issue