Open mysterymath opened 1 month ago
Idea for a seek compatible with any DOS:
int fseek(FILE *stream, long offset, int origin)
{
switch (origin) {
case SEEK_CUR:
if (offset >= 0)
SKIP(offset);
else
return fseek(stream, current_pos + offset, SEEK_SET);
break;
case SEEK_SET:
rewind(stream); // either POINT or CLOSE+OPEN
SKIP(offset);
break;
case SEEK_END:
file_size = current_pos + SKIP_UNTIL_EOF();
if (offset < 0)
return fseek(stream, file_size + offset, SEEK_SET);
break;
}
}
This is of course slow on large files, but standard Atari DOSes read the whole file in order to delete or replace it, so users should be patient enough. :)
One problem is that we cannot SKIP
(nor SKIP_UNTIL_EOF
) on files open in write-only mode.
Meh, generally the ethos behind the C library has been to present a standard interface to functionality already present in the underlying system. This is a stretch along those lines, and it would have a dramatically different time complexity than one would typically expect.
The cc65
lseek
(and thus,fseek
) foratari
only works on Sparta DOS X, since the NOTE/POINT system available on other DOS'es are insufficiently expressive to implement it (since they speak Sectors and Byte offsets, rather than offsets from file begin/end). This limits its usefulness compared to the rest of theatari
POSIX file compat library.