00001
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <string.h>
00007 #include <errno.h>
00008 #include "in.h"
00009
00012 #define EVAL(expr) if (expr) { errno = ENOMEM; perror(pcerr); iret = EXIT_FAILURE; goto cleanup; }
00013
00017 int in(FILE *pf, char **ppc)
00018 {
00019 int iret = EXIT_SUCCESS;
00020 size_t s = 0, scur = 0;
00021 char pcbuf[READ];
00022 const char *pcerr = "in.c in()";
00023 *ppc = (char *) malloc(0);
00024 while ((s = fread(pcbuf, sizeof(char), READ, pf))) {
00025 EVAL((*ppc = (char *) realloc(*ppc, scur + s + sizeof('\0'))) == NULL);
00026 strncpy(*ppc + scur, pcbuf, s);
00027 scur += s;
00028 }
00029 *(*ppc + scur) = '\0';
00030
00031 cleanup:
00032 return iret;
00033 }