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

Commit

Permalink
virtual_file: add function to set position
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 committed Sep 9, 2024
1 parent d23bb2a commit bb732b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/libtrx/virtual_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ VFILE *VFile_CreateFromBuffer(const char *data, size_t size);
void VFile_Close(VFILE *file);

size_t VFile_GetPos(const VFILE *file);
void VFile_SetPos(VFILE *file, size_t pos);
void VFile_Skip(VFILE *file, int32_t offset);

void VFile_Read(VFILE *file, void *target, size_t size);
Expand Down
8 changes: 8 additions & 0 deletions src/virtual_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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;
}

void VFile_Skip(VFILE *file, int32_t offset)
{
const size_t cur_pos = VFile_GetPos(file);
Expand Down

0 comments on commit bb732b4

Please sign in to comment.