summary refs log tree commit diff
diff options
context:
space:
mode:
authorzlago2024-09-01 12:56:46 +0200
committerzlago2024-09-01 12:56:46 +0200
commitaa2a4457dfba11792253937e1ec8e937152b5510 (patch)
tree0895085a5d1b304b61cf6467b585ba74cb7b5c93
parenteb068a88abe0f685309cb1a977f363c7d8708cad (diff)
header
-rw-r--r--src/include.h12
-rw-r--r--src/sdl.c13
2 files changed, 15 insertions, 10 deletions
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);