This patch is a hack used by the followup checkers.cc patch, and ought to be removed in any final version of the kit.
gcc/ChangeLog: * selftest.c (read_file): New overload. * selftest.h (read_file): New overload. --- gcc/selftest.c | 16 +++++++++++++--- gcc/selftest.h | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gcc/selftest.c b/gcc/selftest.c index b41b9f5..a6674be 100644 --- a/gcc/selftest.c +++ b/gcc/selftest.c @@ -162,7 +162,19 @@ read_file (const location &loc, const char *path) FILE *f_in = fopen (path, "r"); if (!f_in) fail_formatted (loc, "unable to open file: %s", path); + char *result = read_file (loc, f_in, path); + fclose (f_in); + return result; +} + +/* Read all of F_IN into memory, returning a 0-terminated buffer + that must be freed by the caller. F_IN is *not* closed. + Fail (and abort) if there are any problems, with LOC as the reported + location of the failure, using DESC as a description of the file. */ +char * +read_file (const location &loc, FILE *f_in, const char *desc) +{ /* Read content, allocating FIXME. */ char *result = NULL; size_t total_sz = 0; @@ -186,11 +198,9 @@ read_file (const location &loc, const char *path) } if (!feof (f_in)) - fail_formatted (loc, "error reading from %s: %s", path, + fail_formatted (loc, "error reading from %s: %s", desc, xstrerror (errno)); - fclose (f_in); - /* 0-terminate the buffer. */ gcc_assert (total_sz < alloc_sz); result[total_sz] = '\0'; diff --git a/gcc/selftest.h b/gcc/selftest.h index e86ce38..541bb71 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -153,6 +153,13 @@ for_each_line_table_case (void (*testcase) (const line_table_case &)); extern char *read_file (const location &loc, const char *path); +/* Read all of F_IN into memory, returning a 0-terminated buffer + that must be freed by the caller. F_IN is *not* closed. + Fail (and abort) if there are any problems, with LOC as the reported + location of the failure, using DESC as a description of the file. */ + +extern char *read_file (const location &loc, FILE *infile, const char *desc); + /* A helper function for writing tests that interact with the garbage collector. */ -- 1.8.5.3