Abstract away file writing logic

This commit is contained in:
Adubbz
2019-08-07 20:43:48 +10:00
parent fac8acebba
commit 7dce15bcda
3 changed files with 26 additions and 40 deletions

View File

@@ -21,6 +21,8 @@
#include "ncm_fs.hpp"
#include "ncm_path_utils.hpp"
#include "debug.hpp"
namespace sts::ncm {
Result OpenFile(FILE** out, const char* path, u32 mode) {
@@ -58,6 +60,26 @@ namespace sts::ncm {
return ResultSuccess;
}
Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option) {
R_DEBUG_START
D_LOG("Writing 0x%llx to offset 0x%llx\n", size, offset);
if (fseek(f, offset, SEEK_SET) != 0) {
return fsdevGetLastResult();
}
if (fwrite(buffer, size, 1, f) != 1) {
return fsdevGetLastResult();
}
if (option & FS_WRITEOPTION_FLUSH) {
fflush(f);
}
return ResultSuccess;
R_DEBUG_END
}
Result HasFile(bool* out, const char* path) {
struct stat st;