From aa2a4457dfba11792253937e1ec8e937152b5510 Mon Sep 17 00:00:00 2001 From: zlago Date: Sun, 1 Sep 2024 12:56:46 +0200 Subject: header --- src/include.h | 12 ++++++++++++ src/sdl.c | 13 +++---------- 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 src/include.h diff --git a/src/include.h b/src/include.h new file mode 100644 index 0000000..a8d48bf --- /dev/null +++ b/src/include.h @@ -0,0 +1,12 @@ +#pragma once + +struct blob { + void *data; + size_t size; +}; + +struct userdata { + SDL_AudioCallback callback; + void *user; + void (*freefunc)(void *); +}; diff --git a/src/sdl.c b/src/sdl.c index 0072c87..18ab7d0 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -11,19 +11,12 @@ static const int WINDOW_WIDTH = 160, WINDOW_HEIGHT = 90; -struct blob { - void *data; - size_t size; -}; - SDL_Window *window = NULL; struct blob load_file(char const *const name); -struct userdata { - SDL_AudioCallback callback; - void *user; -} userdata = { +#include "include.h" +struct userdata userdata = { .callback = NULL, .user = NULL, }; @@ -137,7 +130,7 @@ struct blob load_file(char const *const name) { data = newdata; } void *const newdata = realloc(data, used); - if (newdata == NULL) { + if (newdata == NULL && used != 0) { goto realloc_error; } fclose(file); -- cgit 1.4.1-2-gfad0