#pragma once #include #include static void *drain_error(void) { perror("TZR_LoadResourceTyped:drain"); return NULL; } static char *drain(FILE *fp, size_t *size) { if (fseek(fp, 0, SEEK_END) < 0) return drain_error(); *size = ftell(fp); if (fseek(fp, 0, SEEK_SET) < 0) return drain_error(); char *data = malloc(*size); if (data == NULL) return drain_error(); if (fread(data, 1, *size, fp) != *size) return free(data), drain_error(); return data; }