diff options
| author | nasr <nsrddyn@gmail.com> | 2026-03-03 20:05:11 +0000 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-03-03 20:05:11 +0000 |
| commit | 7165bb7ae9e34e69d0c8802d6e356851cffe0f07 (patch) | |
| tree | c2af6059cb3bcf38277188583af7d41207cf7cc0 /source/base | |
| parent | 4e77bc7164070d7ffafdee1ba6ce3bb1aaf10746 (diff) | |
feature(main): loading and printing csv file
Diffstat (limited to 'source/base')
| -rw-r--r-- | source/base/base_os.h | 41 | ||||
| -rw-r--r-- | source/base/base_string.h | 4 |
2 files changed, 17 insertions, 28 deletions
diff --git a/source/base/base_os.h b/source/base/base_os.h index ec0a3de..23587c6 100644 --- a/source/base/base_os.h +++ b/source/base/base_os.h | |||
| @@ -14,39 +14,24 @@ load_file(const char *path) | |||
| 14 | { | 14 | { |
| 15 | string8 result = {0}; | 15 | string8 result = {0}; |
| 16 | struct stat sbuf = {0}; | 16 | struct stat sbuf = {0}; |
| 17 | int err = 0; | 17 | |
| 18 | i32 file = open(path, O_RDONLY); | 18 | i32 file = open(path, O_RDONLY); |
| 19 | if(file == -1) return result; | ||
| 19 | 20 | ||
| 20 | if(file) | 21 | if(fstat(file, &sbuf) == -1) |
| 21 | { | 22 | { |
| 23 | print("error: fstat failed"); | ||
| 24 | close(file); | ||
| 25 | return result; | ||
| 26 | } | ||
| 22 | 27 | ||
| 23 | if(file != -1) | 28 | result.size = (u64)sbuf.st_size; |
| 24 | { | 29 | if(result.size != 0) |
| 25 | err = fstat(file, &sbuf); | 30 | { |
| 26 | check(err != -1); | 31 | result.data = (u8 *)mmap(0, result.size, PROT_READ, MAP_PRIVATE, file, 0); |
| 27 | |||
| 28 | result.size = (u64)sbuf.st_size; | ||
| 29 | |||
| 30 | if(result.size != 0) | ||
| 31 | { | ||
| 32 | result.data = (u8 *)mmap(0, | ||
| 33 | result.size, | ||
| 34 | PROT_READ, | ||
| 35 | MAP_PRIVATE, | ||
| 36 | file, | ||
| 37 | 0); | ||
| 38 | |||
| 39 | check(result.data != MAP_FAILED); | ||
| 40 | } | ||
| 41 | |||
| 42 | close(file); | ||
| 43 | } | ||
| 44 | else | ||
| 45 | { | ||
| 46 | // TODO(nasr): logging | ||
| 47 | } | ||
| 48 | |||
| 49 | } | 32 | } |
| 33 | |||
| 34 | close(file); | ||
| 50 | return result; | 35 | return result; |
| 51 | } | 36 | } |
| 52 | 37 | ||
diff --git a/source/base/base_string.h b/source/base/base_string.h index 941dc53..64a3162 100644 --- a/source/base/base_string.h +++ b/source/base/base_string.h | |||
| @@ -9,6 +9,10 @@ | |||
| 9 | #define PushString(arena, size) \ | 9 | #define PushString(arena, size) \ |
| 10 | (string8){ (u8 *)PushArray((arena), u8, (size)), (u64)(size) } | 10 | (string8){ (u8 *)PushArray((arena), u8, (size)), (u64)(size) } |
| 11 | 11 | ||
| 12 | #define StringFmt "%.*s" | ||
| 13 | #define ULongFmt "%lu" | ||
| 14 | #define ULLongFmt "%llu" | ||
| 15 | |||
| 12 | typedef struct string8 string8; | 16 | typedef struct string8 string8; |
| 13 | struct string8 | 17 | struct string8 |
| 14 | { | 18 | { |
