#pragma once #include #include static char * drain(FILE *fp, long *size) { if (fseek(fp, 0, SEEK_END) < 0) { perror("drain:SEEK_END"); return NULL; } *size = ftell(fp); if (fseek(fp, 0, SEEK_SET) < 0) { perror("drain:SEEK_SET"); return NULL; } char *const s = malloc(*size + 1); if (s == NULL) { perror("drain:malloc"); return NULL; } if ((long)fread(s, 1, *size, fp) != *size) { perror("drain:fread"); free(s); return NULL; } s[*size] = '\0'; return s; }