4 /* * * * * * * * * * * * *
6 load_file_data loads all the contents of a file into malloc-ed memory.
7 Its argument is the file pointer of the file to read in; the returned
8 result is the NUL terminated contents of the file. The file
9 is presumed to be an ASCII text file containing no NULs. */
15 char *pz_data = (char*)NULL;
16 int space_left = -1; /* allow for terminating NUL */
17 size_t space_used = 0;
23 if (space_left < 1024)
27 pz_data = realloc ((void*)pz_data, space_left + space_used + 1 );
29 pz_data = malloc (space_left + space_used + 1 );
31 size_read = fread (pz_data + space_used, 1, space_left, fp);
42 fprintf (stderr, "error %d (%s) reading input\n", err,
44 free ((void *) pz_data);
50 space_left -= size_read;
51 space_used += size_read;
52 } while (! feof (fp));
54 pz_data = realloc ((void*)pz_data, space_used+1 );
55 pz_data[ space_used ] = NUL;