From 1517f2874ab44fcf210c14e9fdd3f9c1bfd6ba76 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 6 Nov 2023 10:33:45 -0500 Subject: Update - Refactor curl support, add curl websockets - Remove aki_socket config structure - Add the ability to change aki_timer repeat - Various fixes Signed-off-by: Andrew Opalach --- src/util/buffer.c | 19 +++++++++++++++++-- src/util/buffer.h | 5 ++++- src/util/error.h | 2 +- src/util/file/file_linux.c | 2 +- src/util/packet.c | 4 ++-- 5 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src/util') diff --git a/src/util/buffer.c b/src/util/buffer.c index 26e242c..4f184b9 100644 --- a/src/util/buffer.c +++ b/src/util/buffer.c @@ -2,7 +2,7 @@ #define INITIAL_SIZE 128 -void aki_buffer_ensure_size(struct aki_buffer *buf, size_t size) +void aki_buffer_ensure_space(struct aki_buffer *buf, size_t size) { if (buf->alloc >= size) return; if (size < INITIAL_SIZE) buf->alloc = INITIAL_SIZE; @@ -17,14 +17,29 @@ void aki_buffer_init(struct aki_buffer *buf) buf->alloc = 0; } +size_t aki_buffer_get_size(struct aki_buffer *buf) +{ + return buf->size; +} + +void aki_buffer_set_size(struct aki_buffer *buf, size_t size) +{ + buf->size = size; +} + void aki_buffer_write(struct aki_buffer *buf, void *data, size_t index, size_t size) { size_t reach = index + size; - aki_buffer_ensure_size(buf, reach); + aki_buffer_ensure_space(buf, reach); if (reach > buf->size) buf->size = reach; al_memcpy(&buf->data[index], data, size); } +void aki_buffer_append(struct aki_buffer *buf, void *data, size_t size) +{ + aki_buffer_write(buf, data, buf->size, size); +} + u8 *aki_buffer_get_ptr(struct aki_buffer *buf, size_t index) { return &buf->data[index]; diff --git a/src/util/buffer.h b/src/util/buffer.h index 3c40b3a..78d32d5 100644 --- a/src/util/buffer.h +++ b/src/util/buffer.h @@ -10,8 +10,11 @@ struct aki_buffer { }; void aki_buffer_init(struct aki_buffer *buf); -void aki_buffer_ensure_size(struct aki_buffer *buf, size_t size); +void aki_buffer_ensure_space(struct aki_buffer *buf, size_t size); +size_t aki_buffer_get_size(struct aki_buffer *buf); +void aki_buffer_set_size(struct aki_buffer *buf, size_t size); void aki_buffer_write(struct aki_buffer *buf, void *data, size_t index, size_t size); +void aki_buffer_append(struct aki_buffer *buf, void *data, size_t size); u8 *aki_buffer_get_ptr(struct aki_buffer *buf, size_t index); void aki_buffer_read(struct aki_buffer *buf, void *ptr, size_t index, size_t size); void aki_buffer_free(struct aki_buffer *buf); diff --git a/src/util/error.h b/src/util/error.h index d014faa..c7edd82 100644 --- a/src/util/error.h +++ b/src/util/error.h @@ -13,7 +13,7 @@ extern __declspec(thread) char errorbuf[ERROR_STR_MAXLEN]; static inline char *aki_strerror(s32 errnum) { #ifndef _WIN32 - strerror_r(errnum, errorbuf, ERROR_STR_MAXLEN); + (void)!strerror_r(errnum, errorbuf, ERROR_STR_MAXLEN); #else strerror_s(errorbuf, ERROR_STR_MAXLEN, errnum); #endif diff --git a/src/util/file/file_linux.c b/src/util/file/file_linux.c index 97e9688..708bd2d 100644 --- a/src/util/file/file_linux.c +++ b/src/util/file/file_linux.c @@ -158,7 +158,7 @@ bool aki_dir_exists(str *path) bool aki_dir_create(str *path) { char *c_str = al_str_to_c_str(path); - s32 ret = mkdir(c_str, 0700); + s32 ret = mkdir(c_str, 0755); al_free(c_str); if (ret == -1) { al_log_error("file", "mkdir(%.*s) failed (%s).", AL_STR_PRINTF(path), aki_strerror(errno)); diff --git a/src/util/packet.c b/src/util/packet.c index c58d656..9e5a8d7 100644 --- a/src/util/packet.c +++ b/src/util/packet.c @@ -11,7 +11,7 @@ struct aki_packet *aki_packet_create(void) struct aki_packet *aki_packet_clone(struct aki_packet *packet) { struct aki_packet *c = aki_packet_create(); - aki_buffer_ensure_size(&c->buffer, packet->buffer.size); + aki_buffer_ensure_space(&c->buffer, packet->buffer.size); al_memcpy(aki_buffer_get_ptr(&c->buffer, 0), aki_buffer_get_ptr(&packet->buffer, 0), packet->buffer.size); c->windex = packet->windex; c->rindex = packet->rindex; @@ -20,7 +20,7 @@ struct aki_packet *aki_packet_clone(struct aki_packet *packet) void aki_packet_reset(struct aki_packet *packet) { - aki_buffer_ensure_size(&packet->buffer, AKI_PACKET_HEADER_LENGTH); + aki_buffer_ensure_space(&packet->buffer, AKI_PACKET_HEADER_LENGTH); packet->rindex = AKI_PACKET_HEADER_LENGTH; packet->windex = AKI_PACKET_HEADER_LENGTH; } -- cgit v1.2.3-101-g0448