Allocate just enough to read the input file.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 19 Feb 2009 03:09:26 -0500
changeset 662 50ff6f3eaa4f
parent 661 a502c4999238
child 663 e7b3b60bd3b1
Allocate just enough to read the input file.
utils/preprocess.c
--- a/utils/preprocess.c	Thu Feb 19 01:46:18 2009 -0500
+++ b/utils/preprocess.c	Thu Feb 19 03:09:26 2009 -0500
@@ -210,8 +210,13 @@
         printf(" ... fopen('%s') failed.\n", infile);
     else
     {
-        char *buf = (char *) malloc(1000000);
-        int rc = fread(buf, 1, 1000000, io);
+        fseek(io, 0, SEEK_END);
+        long fsize = ftell(io);
+        fseek(io, 0, SEEK_SET);
+        if (fsize == -1)
+            fsize = 1000000;
+        char *buf = (char *) malloc(fsize);
+        const int rc = fread(buf, 1, fsize, io);
         fclose(io);
         if (rc == EOF)
             printf(" ... fread('%s') failed.\n", infile);