mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-05 00:40:48 -08:00
Merging the extra bits of the byte buffer is tricky when the file was opened only for output.
This commit is contained in:
parent
9ef76ef614
commit
b6c8edfb73
1 changed files with 17 additions and 0 deletions
17
src/c/file.d
17
src/c/file.d
|
|
@ -782,6 +782,23 @@ flush_output_stream_binary(cl_object strm)
|
|||
if (c != EOF)
|
||||
b |= (unsigned char)(c & ~MAKE_BIT_MASK(nb));
|
||||
fseek(strm->stream.file, -1, SEEK_CUR);
|
||||
} else {
|
||||
/* Tricky part -> check whether we are at the EOF */
|
||||
long current_offset = ftell(strm->stream.file);
|
||||
fseek(strm->stream.file, 0, SEEK_END);
|
||||
if (ftell(strm->stream.file) - current_offset > 0) {
|
||||
/* No, we weren't at the EOF, try merging. *
|
||||
* As the file was opened only for writing, *
|
||||
* this mean re-opening the file... */
|
||||
cl_object fn = si_coerce_to_filename(strm->stream.object1);
|
||||
fseek(freopen(fn->string.self, "rb", strm->stream.file),
|
||||
current_offset,
|
||||
SEEK_SET);
|
||||
b |= (unsigned char)(ecl_read_byte8(strm) & ~MAKE_BIT_MASK(nb));
|
||||
fseek(freopen(fn->string.self, "wb", strm->stream.file),
|
||||
current_offset,
|
||||
SEEK_SET);
|
||||
}
|
||||
}
|
||||
ecl_write_byte8(b, strm);
|
||||
fseek(strm->stream.file, -1, SEEK_CUR); /* I/O synchronization */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue