summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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);