From b047be5252aeb981faea077409c1768fda0301d9 Mon Sep 17 00:00:00 2001 From: Omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:43:13 +1100 Subject: xmake init with shared/static lib --- src/defines.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/platform/file.c | 29 +++++++++++++++++++++++++++++ src/platform/file.h | 11 +++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/defines.h create mode 100644 src/platform/file.c create mode 100644 src/platform/file.h (limited to 'src') diff --git a/src/defines.h b/src/defines.h new file mode 100644 index 0000000..2129d94 --- /dev/null +++ b/src/defines.h @@ -0,0 +1,44 @@ +/** + * @file defines.h + * @author your name (you@domain.com) + * @brief + * @date 2024-02-24 + * @copyright Copyright (c) 2024 + */ +#pragma once + +#include +#include +#include + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; + +typedef float f32; +typedef double f64; + +_Static_assert(sizeof(bool) == 1, "type bool should be 1 byte"); + +_Static_assert(sizeof(u8) == 1, "type u8 should be 1 byte"); +_Static_assert(sizeof(u16) == 2, "type u16 should be 2 byte"); +_Static_assert(sizeof(u32) == 4, "type u32 should be 4 byte"); +_Static_assert(sizeof(u64) == 8, "type u64 should be 8 byte"); + +_Static_assert(sizeof(i8) == 1, "type i8 should be 1 byte"); +_Static_assert(sizeof(i16) == 2, "type i16 should be 2 byte"); +_Static_assert(sizeof(i32) == 4, "type i32 should be 4 byte"); +_Static_assert(sizeof(i64) == 8, "type i64 should be 8 byte"); + +_Static_assert(sizeof(f32) == 4, "type f32 should be 4 bytes"); +_Static_assert(sizeof(f64) == 8, "type f64 should be 8 bytes"); + +_Static_assert(sizeof(ptrdiff_t) == 8, ""); + +#define alignof(x) _Alignof(x) \ No newline at end of file diff --git a/src/platform/file.c b/src/platform/file.c new file mode 100644 index 0000000..497a95c --- /dev/null +++ b/src/platform/file.c @@ -0,0 +1,29 @@ +#include "file.h" + +#include +#include +#include +#include + +const char *string_from_file(const char *path) { + FILE *f = fopen(path, "rb"); + if (f == NULL) { + // ERROR("Error reading file: %s. errno: %d", path, errno); + return NULL; + } + if (ferror(f)) { + // ERROR("Error reading file: %s. errno: %d", path, errno); + return NULL; + } + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + rewind(f); + + char *string = malloc(fsize + 1); + fread(string, fsize, 1, f); + fclose(f); + + string[fsize] = '\0'; + + return string; +} \ No newline at end of file diff --git a/src/platform/file.h b/src/platform/file.h new file mode 100644 index 0000000..b965ceb --- /dev/null +++ b/src/platform/file.h @@ -0,0 +1,11 @@ +/** + * @file file.h + * @brief File I/O utilities + * @date 2024-02-24 + * @copyright Copyright (c) 2024 + */ +#pragma once + +#include + +const char* string_from_file(const char* path); -- cgit v1.2.3-70-g09d2