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