aboutsummaryrefslogtreecommitdiff
path: root/gcc/fixinc/fixlib.c
diff options
context:
space:
mode:
authorBruce Korb <autogen@linuxbox.com>1999-10-12 14:44:18 +0000
committerBruce Korb <korbb@gcc.gnu.org>1999-10-12 14:44:18 +0000
commit5abc1f741e8c34c725524c985af7d509c68165ad (patch)
treeb7c04700ad0597627b75bc451b012da96f57a002 /gcc/fixinc/fixlib.c
parent9e15ef052036441d9cd932891c2176d2a12f3d7a (diff)
downloadgcc-5abc1f741e8c34c725524c985af7d509c68165ad.zip
gcc-5abc1f741e8c34c725524c985af7d509c68165ad.tar.gz
gcc-5abc1f741e8c34c725524c985af7d509c68165ad.tar.bz2
Merge from no_bogosity
From-SVN: r29918
Diffstat (limited to 'gcc/fixinc/fixlib.c')
-rw-r--r--gcc/fixinc/fixlib.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/fixinc/fixlib.c b/gcc/fixinc/fixlib.c
new file mode 100644
index 0000000..25a672e
--- /dev/null
+++ b/gcc/fixinc/fixlib.c
@@ -0,0 +1,56 @@
+
+#include "fixlib.h"
+
+/* * * * * * * * * * * * *
+
+ load_file_data loads all the contents of a file into malloc-ed memory.
+ Its argument is the file pointer of the file to read in; the returned
+ result is the NUL terminated contents of the file. The file
+ is presumed to be an ASCII text file containing no NULs. */
+
+char *
+load_file_data (fp)
+ FILE* fp;
+{
+ char *pz_data = (char*)NULL;
+ int space_left = -1; /* allow for terminating NUL */
+ size_t space_used = 0;
+
+ do
+ {
+ size_t size_read;
+
+ if (space_left < 1024)
+ {
+ space_left += 4096;
+ pz_data = realloc ((void*)pz_data, space_left + space_used + 1 );
+ }
+ size_read = fread (pz_data + space_used, 1, space_left, fp);
+
+ if (size_read == 0)
+ {
+ if (feof (fp))
+ break;
+
+ if (ferror (fp))
+ {
+ int err = errno;
+ if (err != EISDIR)
+ fprintf (stderr, "error %d (%s) reading input\n", err,
+ strerror (err));
+ free ((void *) pz_data);
+ fclose (fp);
+ return (char *) NULL;
+ }
+ }
+
+ space_left -= size_read;
+ space_used += size_read;
+ } while (! feof (fp));
+
+ pz_data = realloc ((void*)pz_data, space_used+1 );
+ pz_data[ space_used ] = NUL;
+ fclose (fp);
+
+ return pz_data;
+}