From e24186fc1917c5e8b91924af0c3c7c55816ff5d6 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 25 Jan 2021 22:01:00 +0100 Subject: Introducing MIC --- src/platform.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/platform.h (limited to 'src/platform.h') diff --git a/src/platform.h b/src/platform.h new file mode 100644 index 0000000..877453c --- /dev/null +++ b/src/platform.h @@ -0,0 +1,25 @@ +#ifndef MIC_PLATFORM_H +#define MIC_PLATFORM_H + +// Function pointers for the PlatformAPI. This allows the app to call platform +// specific functions that perform IO, memory allocations, etc. +typedef struct PlatformAPI { + // Reads an entire file into a null terminated buffer. It doesn't perform + // memory allocations and may crash if there is not enough memory or if it + // is uninitialized. Returns the number of bytes read. + size_t (*read_file)(const char *path, char *memory); + + // Custom memory allocation functions for the platform. + void *(*malloc)(size_t size); + void (*free)(void *ptr); + void *(*calloc)(size_t nmemb, size_t size); + void *(*realloc)(void *ptr, size_t size); + + // Sleep/wait for a given number of microseconds. + void (*sleep)(size_t microseconds); + + // Logging functions. + void (*log)(const char *format, ...); +} PlatformAPI; + +#endif // MIC_PLATFORM_H -- cgit v1.2.1