Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port atari Sparta DOS X lseek from cc65 #333

Open
mysterymath opened this issue Jun 2, 2024 · 2 comments
Open

Port atari Sparta DOS X lseek from cc65 #333

mysterymath opened this issue Jun 2, 2024 · 2 comments
Labels
enhancement New feature or request p2

Comments

@mysterymath
Copy link
Member

The cc65 lseek (and thus, fseek) for atari 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 the atari POSIX file compat library.

@mysterymath mysterymath added enhancement New feature or request p2 labels Jun 2, 2024
@pfusik
Copy link
Contributor

pfusik commented Jun 20, 2024

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.

@mysterymath
Copy link
Member Author

mysterymath commented Jun 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2
Projects
None yet
Development

No branches or pull requests

2 participants