From 6d30e75c7684817b9637a370f494040a1135b876 Mon Sep 17 00:00:00 2001 From: zlago Date: Mon, 2 Sep 2024 11:20:02 +0200 Subject: un-copy paste some stuff --- src/SDL2.c | 52 +--------------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) (limited to 'src/SDL2.c') diff --git a/src/SDL2.c b/src/SDL2.c index 4e51269..79b4e4a 100644 --- a/src/SDL2.c +++ b/src/SDL2.c @@ -6,9 +6,7 @@ #include #include "include.h" - -int module_openmpt(struct blob *file, struct userdata *userdata); -int module_fluidsynth(struct blob *file, struct userdata *userdata); +#include "common/common.h" #define eprintf(...) fprintf(stderr, __VA_ARGS__) @@ -171,51 +169,3 @@ int main(int argc, char **argv) { return EXIT_SUCCESS; } - -int (*file_ext(char *file))(struct blob *, struct userdata *) { - size_t len = strlen(file); - #define ext(extension) memcmp(file + len - sizeof (extension) + 1, extension, sizeof (extension)) - if ((ext(".mptm") && ext(".mod") && ext(".xm") && ext(".s3m") && ext(".it")) == 0) { - return module_openmpt; - } else if ((ext(".mid") && ext(".midi")) == 0) { - return module_fluidsynth; - } - #undef ext - return NULL; -} - -struct blob load_file(char const *const name) { - const size_t START_SIZE = 1; - FILE *file = fopen(name, "rb"); - if (file == NULL) { - return (struct blob) {.data = NULL}; - } - void *data = malloc(START_SIZE); - size_t allocated = START_SIZE; - size_t used = 0; - while (1) { - size_t read = fread(data + used, 1, allocated - used, file); - if (read != allocated - used) { - used += read; - break; - } - used += read; - allocated *= 2; - void *const newdata = realloc(data, allocated); - if (newdata == NULL) { - goto realloc_error; - } - data = newdata; - } - void *const newdata = realloc(data, used); - if (newdata == NULL && used != 0) { - goto realloc_error; - } - fclose(file); - return (struct blob) {.data = newdata, .size = used}; - - realloc_error: - free(data); - fclose(file); - return (struct blob) {.data = NULL}; -} -- cgit 1.4.1-2-gfad0