Update wapp array C API

This commit is contained in:
2025-12-07 21:56:16 +00:00
committed by Abdelrahman Said
parent 551836d4c8
commit 2b49bfcdbf
10 changed files with 365 additions and 3991 deletions

View File

@@ -66,8 +66,8 @@ u64 wapp_file_read(GenericArray *dst, File *file, u64 item_count) {
"`dst`, `dst->items` and `file` should not be NULL.");
u64 file_length = wapp_file_get_length(file);
u64 dst_byte_capacity = dst->item_size * dst->capacity;
u64 req_byte_count = item_count * dst->item_size;
u64 dst_byte_capacity = dst->header.item_size * dst->header.capacity;
u64 req_byte_count = item_count * dst->header.item_size;
u64 copy_byte_count = 0;
if (req_byte_count <= file_length && req_byte_count <= dst_byte_capacity) {
@@ -76,17 +76,17 @@ u64 wapp_file_read(GenericArray *dst, File *file, u64 item_count) {
copy_byte_count = file_length <= dst_byte_capacity ? file_length : dst_byte_capacity;
}
dst->count = fread(dst->items, sizeof(u8), copy_byte_count, file) / dst->item_size;
dst->header.count = fread(dst->items, sizeof(u8), copy_byte_count, file) / dst->header.item_size;
return dst->count;
return dst->header.count;
}
u64 wapp_file_write(const GenericArray *src, File *file, u64 item_count) {
wapp_debug_assert(src != NULL && src->items != NULL && file != NULL,
"`src`, `src->items` and `file` should not be NULL.");
u64 src_byte_count = src->count * src->item_size;
u64 req_byte_count = item_count * src->item_size;
u64 src_byte_count = src->header.count * src->header.item_size;
u64 req_byte_count = item_count * src->header.item_size;
u64 to_copy = req_byte_count <= src_byte_count ? req_byte_count : src_byte_count;
return fwrite(src->items, sizeof(u8), to_copy, file);