Wrapper to turn romfs_file into romfs_fileobj

Useful for turning romfs_direntry files into readable files
This commit is contained in:
James Bulman 2024-06-14 15:49:11 +01:00
parent 13d880fe12
commit 6218f4875c
2 changed files with 18 additions and 0 deletions

View File

@ -161,6 +161,14 @@ Result romfsFindFile(const char *path, romfs_fileobj *file);
*/
Result romfsFindFileInMount(romfs_mount *mount, const char *path, romfs_fileobj *file);
/**
* @brief Wrapper function for turning a romfs_file into a romfs_fileobj to be operated on, this
* is useful for creating readable files from a romfs_direntry
* @param mount The mount the file came from
* @param file The file information
*/
romfs_fileobj romfsFileObj(romfs_mount *mount, romfs_file *file);
/**
* @brief Reads data from the specified RomFS file.
* @param file The RomFS file to read from.

View File

@ -685,6 +685,16 @@ Result romfsFindFileInMount(romfs_mount *mount, const char *path, romfs_fileobj
return 0;
}
romfs_fileobj romfsFileObj(romfs_mount *mount, romfs_file *file)
{
romfs_fileobj result = { 0 };
result.mount = mount;
result.file = file;
result.offset = mount->header.fileDataOff + file->dataOff;
return result;
}
Result romfsReadFile(romfs_fileobj *file, void *buffer, u64 size, u64 offset, u64 *nread)
{
if (nread == NULL || file == NULL || buffer == NULL)