Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

virtual_file: add function to set position #26

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

lahm86
Copy link
Collaborator

@lahm86 lahm86 commented Sep 9, 2024

Basically a seek function for convenience, but I went with a similar name to GetPos.

@lahm86 lahm86 self-assigned this Sep 9, 2024
@lahm86 lahm86 requested a review from a team as a code owner September 9, 2024 15:31
@lahm86 lahm86 requested review from rr- and walkawayy and removed request for a team September 9, 2024 15:31
@@ -53,6 +53,14 @@ size_t VFile_GetPos(const VFILE *file)
return file->cur_ptr - file->content;
}

void VFile_SetPos(VFILE *file, const size_t pos)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: VFILE *const file

const size_t cur_pos = VFile_GetPos(file);
const int32_t offset = pos - cur_pos;
assert(cur_pos + offset <= file->size);
file->cur_ptr += offset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just go with file->cur_ptr = file->content + pos, and add an assertion that pos >= 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks. Left the assert doing an upper check as size_t is unsigned (produces a warning adding it).

@lahm86 lahm86 merged commit 2d3b35f into LostArtefacts:main Sep 10, 2024
1 check passed
@lahm86 lahm86 deleted the add-vfile-setpos branch September 10, 2024 07:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants