file_readWhole

This commit is contained in:
2025-11-18 14:18:09 +05:00
parent 89aab2b5bf
commit bc41577248
2 changed files with 18 additions and 0 deletions

View File

@@ -124,3 +124,17 @@ Result(void) file_readStructsExactly(FILE* f, void* dst, u64 struct_size, u64 ex
}
return RESULT_VOID;
}
Result(void) file_readWhole(FILE* f, Array(u8)* out_buf){
Deferral(1);
bool success = false;
try(i64 f_size, i, file_getSize(f));
Array(u8) buf = Array_alloc(u8, f_size);
Defer(if(!success) free(buf.data));
try_void(file_readBytesArray(f, buf));
*out_buf = buf;
success = true;
Return RESULT_VOID;
}