diff options
| author | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-03-30 13:48:56 +1100 |
|---|---|---|
| committer | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-03-30 13:48:56 +1100 |
| commit | 84a34fcd489187279e54201e9b56e049b5048892 (patch) | |
| tree | 2e28ba2226b3b87e6147b7f76f1fafcf783dd307 /src/common.c | |
| parent | 5b8137cfa32615a72380e65481f7561333d50007 (diff) | |
feat(common): Create ff_ctx initialiser
Diffstat (limited to 'src/common.c')
| -rw-r--r-- | src/common.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index ad7be7b..c0bf478 100644 --- a/src/common.c +++ b/src/common.c @@ -1,5 +1,41 @@ +#include <tinyff/dbg.h> #include <tinyff/common.h> +#ifdef USE_HOSTED +#include <stdlib.h> +#endif + + +// Initializes a new tinyff context. +ff_ctx* ff_init(ff_allocator* allocator) +{ + +#ifdef USE_HOSTED + ff_allocator default_alloc = { malloc, free, calloc }; + if (!allocator) allocator = &default_alloc; +#else + if (!allocator) return NULL; +#endif + + ff_ctx* ctx = allocator->ff_alloc(sizeof(ff_ctx)); + + if (!ctx) return NULL; + + ctx->ff_debug_enabled = FF_DISABLE; + ctx->ff_debug_stream = NULL; + + ctx->allocator = *allocator; + + return ctx; +} + +void ff_cleanup(ff_ctx *ctx) { + if (!ctx) return; + ff_dprintf(ctx, "goodbye from tinyff ;]"); + ctx->allocator.ff_free(ctx); + +} + // Endian functions moved to header because C's acting up again // Anyway, while you're here, lets have a talk. // Listen, life isnt easy. but listen, storms make stronger sailors. |
