_sion_file_set_position_ansi and _sion_file_get_position_ansi use POSIX functions on some platforms
E.g., on Linux, said functions reach around the C standard FILE*
via fileno()
and modify/inspect the position of the POSIX file descriptor directly via lseek()
. This leads to confusing results by making the buffering that C standard I/O performs observable, e.g. in a sequence read -> set_position -> read
the second read
can return bytes that were read by the first read
and still remain in the I/O buffer.
This behavior is not consistent with POSIX (where no buffering is performed) or the C standard library (where fseek
transparently flushes buffer as necessary) or even with itself (on mac OS (Darwin) _sion_file_set_position_ansi
is implemented via fseek
).
To paper over the inconsistency most (but not all) uses of _sion_file_set_position()
and _sion_file_get_position()
in SIONlib are prefixed with an explicit _sion_file_flush()
.
Changing the implementation of the functions in question to use fseek
and ftello
like on mac OS does not break anything. In fact, after doing so, it is possible to remove _sion_file_flush
from all sequences _sion_file_flush -> _sion_file_{get|set}_position
without breaking any tests.
== Question
Is there a reason for _sion_file_{get|set}_position_ansi
being implemented the way they are or can they be changed to be more consistent?