diff options
| -rw-r--r-- | jrk.h | 38 |
1 files changed, 21 insertions, 17 deletions
@@ -11,6 +11,8 @@ * - add an arg parsing api. * * - add real random api. and remove the rand() wrappers. + * + * - add platform layer stuff. */ #include <stdbool.h> @@ -29,6 +31,8 @@ typedef uint64_t u64; typedef float f32; typedef double f64; +typedef int jrk_fd; + #define _JRK_MAX_STRNLEN 1024 #define _JRK_DEFAULT_ALIGNMENT (2*sizeof(uintptr_t)) @@ -82,11 +86,11 @@ void *jrk_arena_resize(jrk_Arena*, void*, u64, u64); i32 jrk_rand_num(i32); i32 jrk_rand_num_range(i32, i32); -i32 jrk_fd_open_read(const char*); -i32 jrk_fd_open_write(const char*); -i32 jrk_fd_open_write_append(const char*); -bool jrk_fd_size(i32, u64*); -void jrk_fd_close(i32); +jrk_fd jrk_fd_open_read(const char*); +jrk_fd jrk_fd_open_write(const char*); +jrk_fd jrk_fd_open_write_append(const char*); +bool jrk_fd_size(jrk_fd, u64*); +void jrk_fd_close(jrk_fd); jrk_String jrk_string_from_parts(const char*, u64); jrk_String jrk_string_trim_right(jrk_String); @@ -590,7 +594,7 @@ jrk_sb_append_buf_at(jrk_String_Builder *sb, const char *buf, u64 buf_sz, u64 id } bool -jrk_sb_fd_read_all(jrk_String_Builder *sb, i32 fd) +jrk_sb_fd_read_all(jrk_String_Builder *sb, jrk_fd fd) { bool result = true; u64 filesize = 0; @@ -608,7 +612,7 @@ defer: } bool -jrk_sb_fd_write(jrk_String_Builder *sb, i32 fd) +jrk_sb_fd_write(jrk_String_Builder *sb, jrk_fd fd) { i64 result; result = write(fd, (void *) sb->items, sb->len); @@ -624,7 +628,7 @@ bool jrk_sb_read_entire_file(jrk_String_Builder *sb, const char *filename) { bool result = true; - i32 fd = jrk_fd_open_read(filename); + jrk_fd fd = jrk_fd_open_read(filename); if (fd < 0) return false; if (!jrk_sb_fd_read_all(sb, fd)) jrk_return_defer(false); @@ -637,7 +641,7 @@ bool jrk_sb_write_entire_file(jrk_String_Builder *sb, const char *filename) { bool result = true; - i32 fd = jrk_fd_open_write(filename); + jrk_fd fd = jrk_fd_open_write(filename); if (fd < 0) return false; if (!jrk_sb_fd_write(sb, fd)) jrk_return_defer(false); @@ -792,7 +796,7 @@ jrk_arena_reset(jrk_Arena *arena) } bool -jrk_fd_size(i32 fd, u64 *size) +jrk_fd_size(jrk_fd fd, u64 *size) { if (!size) { jrk_errorv("jrk_fd_size(%d, %p): size ptr is NULL", fd, (void *) size); @@ -810,15 +814,15 @@ jrk_fd_size(i32 fd, u64 *size) } void -jrk_fd_close(i32 fd) +jrk_fd_close(jrk_fd fd) { close(fd); } -i32 +jrk_fd jrk_fd_open_read(const char *path) { - i32 result = open(path, O_RDONLY); + jrk_fd result = open(path, O_RDONLY); if (result < 0) { jrk_eerrorv("jrk_fd_open_read(%s)", path); @@ -828,10 +832,10 @@ jrk_fd_open_read(const char *path) return result; } -i32 +jrk_fd jrk_fd_open_write(const char *path) { - i32 result = open(path, + jrk_fd result = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); @@ -843,10 +847,10 @@ jrk_fd_open_write(const char *path) return result; } -i32 +jrk_fd jrk_fd_open_write_append(const char *path) { - i32 result = open(path, + jrk_fd result = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
