Switch to using tabs instead of spaces (#9)

Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
2025-12-29 22:46:52 +00:00
parent aa6ef1ec2c
commit ad2de98093
60 changed files with 3772 additions and 3772 deletions

View File

@@ -9,101 +9,101 @@
#include <stdio.h>
File *wapp_file_open(Str8RO *filepath, FileAccessMode mode) {
wapp_persist const char *modes[FILE_ACCESS_MODE_COUNT] = {
[WAPP_FA_MODE_R] = "r",
[WAPP_FA_MODE_W] = "w",
[WAPP_FA_MODE_A] = "a",
[WAPP_FA_MODE_R_EX] = "r+",
[WAPP_FA_MODE_W_EX] = "w+",
[WAPP_FA_MODE_A_EX] = "a+",
[WAPP_FA_MODE_RB] = "rb",
[WAPP_FA_MODE_WB] = "wb",
[WAPP_FA_MODE_AB] = "ab",
[WAPP_FA_MODE_RB_EX] = "rb+",
[WAPP_FA_MODE_WB_EX] = "wb+",
[WAPP_FA_MODE_AB_EX] = "ab+",
[WAPP_FA_MODE_WX] = "wx",
[WAPP_FA_MODE_WX_EX] = "wx+",
[WAPP_FA_MODE_WBX] = "wbx",
[WAPP_FA_MODE_WBX_EX] = "wbx+",
};
wapp_persist c8 tmp[WAPP_PATH_MAX] = {0};
wapp_debug_assert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
wapp_persist const char *modes[FILE_ACCESS_MODE_COUNT] = {
[WAPP_FA_MODE_R] = "r",
[WAPP_FA_MODE_W] = "w",
[WAPP_FA_MODE_A] = "a",
[WAPP_FA_MODE_R_EX] = "r+",
[WAPP_FA_MODE_W_EX] = "w+",
[WAPP_FA_MODE_A_EX] = "a+",
[WAPP_FA_MODE_RB] = "rb",
[WAPP_FA_MODE_WB] = "wb",
[WAPP_FA_MODE_AB] = "ab",
[WAPP_FA_MODE_RB_EX] = "rb+",
[WAPP_FA_MODE_WB_EX] = "wb+",
[WAPP_FA_MODE_AB_EX] = "ab+",
[WAPP_FA_MODE_WX] = "wx",
[WAPP_FA_MODE_WX_EX] = "wx+",
[WAPP_FA_MODE_WBX] = "wbx",
[WAPP_FA_MODE_WBX_EX] = "wbx+",
};
wapp_persist c8 tmp[WAPP_PATH_MAX] = {0};
wapp_debug_assert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
return fopen((const char *)tmp, modes[mode]);
return fopen((const char *)tmp, modes[mode]);
}
u64 wapp_file_get_current_position(File *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
return (u64)ftell(file);
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
return (u64)ftell(file);
}
i32 wapp_file_seek(File *file, u64 offset, FileSeekOrigin origin) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
// TODO (Abdelrahman): Revisit conversion to long
return fseek(file, (long)offset, origin);
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
// TODO (Abdelrahman): Revisit conversion to long
return fseek(file, (long)offset, origin);
}
u64 wapp_file_get_length(File *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
u64 current = wapp_file_get_current_position(file);
u64 current = wapp_file_get_current_position(file);
wapp_file_seek(file, 0, WAPP_SEEK_END);
wapp_file_seek(file, 0, WAPP_SEEK_END);
u64 output = ftell(file);
u64 output = ftell(file);
// Restore position
wapp_file_seek(file, current, WAPP_SEEK_START);
// Restore position
wapp_file_seek(file, current, WAPP_SEEK_START);
return output;
return output;
}
u64 wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count) {
wapp_debug_assert(dst_buf != NULL && file != NULL,
"`dst_buf` and `file` should not be NULL.");
wapp_debug_assert(dst_buf != NULL && file != NULL,
"`dst_buf` and `file` should not be NULL.");
u64 file_length = wapp_file_get_length(file);
u64 item_size = dst_buf->item_size;
u64 dst_byte_capacity = dst_buf->capacity * item_size;
u64 req_byte_count = item_count * item_size;
u64 copy_byte_count = 0;
u64 file_length = wapp_file_get_length(file);
u64 item_size = dst_buf->item_size;
u64 dst_byte_capacity = dst_buf->capacity * item_size;
u64 req_byte_count = item_count * item_size;
u64 copy_byte_count = 0;
if (req_byte_count <= file_length && req_byte_count <= dst_byte_capacity) {
copy_byte_count = req_byte_count;
} else {
copy_byte_count = file_length <= dst_byte_capacity ? file_length : dst_byte_capacity;
}
if (req_byte_count <= file_length && req_byte_count <= dst_byte_capacity) {
copy_byte_count = req_byte_count;
} else {
copy_byte_count = file_length <= dst_byte_capacity ? file_length : dst_byte_capacity;
}
u64 count = fread(dst_buf->items, sizeof(u8), copy_byte_count, file);
if (ferror(file)) { return 0; }
u64 count = fread(dst_buf->items, sizeof(u8), copy_byte_count, file);
if (ferror(file)) { return 0; }
dst_buf->count = count / item_size;
dst_buf->count = count / item_size;
return dst_buf->count;
return dst_buf->count;
}
u64 wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count) {
wapp_debug_assert(src_buf != NULL && file != NULL,
"`src_buf` and `file` should not be NULL.");
wapp_debug_assert(src_buf != NULL && file != NULL,
"`src_buf` and `file` should not be NULL.");
u64 item_size = src_buf->item_size;
u64 src_byte_count = src_buf->count * item_size;
u64 req_byte_count = item_count * item_size;
u64 to_copy = req_byte_count <= src_byte_count ? req_byte_count : src_byte_count;
u64 item_size = src_buf->item_size;
u64 src_byte_count = src_buf->count * item_size;
u64 req_byte_count = item_count * item_size;
u64 to_copy = req_byte_count <= src_byte_count ? req_byte_count : src_byte_count;
return fwrite(src_buf->items, sizeof(u8), to_copy, file);
return fwrite(src_buf->items, sizeof(u8), to_copy, file);
}
i32 wapp_file_flush(File *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
return fflush(file);
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
return fflush(file);
}
i32 wapp_file_close(File *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
return fclose(file);
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
return fclose(file);
}

View File

@@ -14,40 +14,40 @@ BEGIN_C_LINKAGE
typedef FILE File;
typedef enum {
WAPP_FA_MODE_R, // Equivalent to r
WAPP_FA_MODE_W, // Equivalent to w
WAPP_FA_MODE_A, // Equivalent to a
WAPP_FA_MODE_R_EX, // Equivalent to r+
WAPP_FA_MODE_W_EX, // Equivalent to w+
WAPP_FA_MODE_A_EX, // Equivalent to a+
WAPP_FA_MODE_RB, // Equivalent to rb
WAPP_FA_MODE_WB, // Equivalent to wb
WAPP_FA_MODE_AB, // Equivalent to ab
WAPP_FA_MODE_RB_EX, // Equivalent to rb+
WAPP_FA_MODE_WB_EX, // Equivalent to wb+
WAPP_FA_MODE_AB_EX, // Equivalent to ab+
WAPP_FA_MODE_WX, // Equivalent to wx
WAPP_FA_MODE_WX_EX, // Equivalent to wx+
WAPP_FA_MODE_WBX, // Equivalent to wbx
WAPP_FA_MODE_WBX_EX, // Equivalent to wbx+
WAPP_FA_MODE_R, // Equivalent to r
WAPP_FA_MODE_W, // Equivalent to w
WAPP_FA_MODE_A, // Equivalent to a
WAPP_FA_MODE_R_EX, // Equivalent to r+
WAPP_FA_MODE_W_EX, // Equivalent to w+
WAPP_FA_MODE_A_EX, // Equivalent to a+
WAPP_FA_MODE_RB, // Equivalent to rb
WAPP_FA_MODE_WB, // Equivalent to wb
WAPP_FA_MODE_AB, // Equivalent to ab
WAPP_FA_MODE_RB_EX, // Equivalent to rb+
WAPP_FA_MODE_WB_EX, // Equivalent to wb+
WAPP_FA_MODE_AB_EX, // Equivalent to ab+
WAPP_FA_MODE_WX, // Equivalent to wx
WAPP_FA_MODE_WX_EX, // Equivalent to wx+
WAPP_FA_MODE_WBX, // Equivalent to wbx
WAPP_FA_MODE_WBX_EX, // Equivalent to wbx+
FILE_ACCESS_MODE_COUNT,
FILE_ACCESS_MODE_COUNT,
} FileAccessMode;
typedef enum {
WAPP_SEEK_START = SEEK_SET,
WAPP_SEEK_CURRENT = SEEK_CUR,
WAPP_SEEK_END = SEEK_END,
WAPP_SEEK_START = SEEK_SET,
WAPP_SEEK_CURRENT = SEEK_CUR,
WAPP_SEEK_END = SEEK_END,
} FileSeekOrigin;
File *wapp_file_open(Str8RO *filename, FileAccessMode mode);
u64 wapp_file_get_current_position(File *file);
i32 wapp_file_seek(File *file, u64 offset, FileSeekOrigin origin);
u64 wapp_file_get_length(File *file);
u64 wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count);
u64 wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count);
i32 wapp_file_flush(File *file);
i32 wapp_file_close(File *file);
File *wapp_file_open(Str8RO *filename, FileAccessMode mode);
u64 wapp_file_get_current_position(File *file);
i32 wapp_file_seek(File *file, u64 offset, FileSeekOrigin origin);
u64 wapp_file_get_length(File *file);
u64 wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count);
u64 wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count);
i32 wapp_file_flush(File *file);
i32 wapp_file_close(File *file);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE