From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 09/22] Add selftest::read_file (..., FILE *, ...)
Date: Fri, 04 Aug 2017 21:36:00 -0000 [thread overview]
Message-ID: <1501884293-9047-10-git-send-email-dmalcolm@redhat.com> (raw)
In-Reply-To: <1501884293-9047-1-git-send-email-dmalcolm@redhat.com>
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
next prev parent reply other threads:[~2017-08-04 21:36 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-04 21:30 [PATCH 00/22] RFC: integrated 3rd-party static analysis support David Malcolm
2017-08-04 21:30 ` [PATCH 02/22] libcpp: add linemap_position_for_file_line_and_column David Malcolm
2017-09-01 17:50 ` Jeff Law
2017-08-04 21:30 ` [PATCH 01/22] Expose assert_loceq outside of input.c; add ASSERT_LOCEQ David Malcolm
2017-09-01 17:49 ` Jeff Law
2017-08-04 21:30 ` [PATCH 03/22] Add JSON implementation David Malcolm
2017-09-01 17:56 ` Jeff Law
2017-08-04 21:36 ` [PATCH 17/22] Add checkers/cppcheck.py David Malcolm
2017-08-04 21:36 ` [PATCH 07/22] Add minimal version of Nick Clifton's annobin code David Malcolm
2017-09-01 18:17 ` Jeff Law
2017-08-04 21:36 ` [PATCH 19/22] Add checkers/ianal.py David Malcolm
2017-08-04 21:36 ` [PATCH 16/22] Add checkers/coverity.py David Malcolm
2017-08-04 21:36 ` [PATCH 08/22] Add GNU_BUILD_ATTRIBUTE_STATIC_ANALYSIS to annobin.h David Malcolm
2017-08-04 21:36 ` [PATCH 10/22] Add checkers.h/cc David Malcolm
2017-08-04 21:36 ` David Malcolm [this message]
2017-08-04 21:36 ` [PATCH 22/22] Add contrib/get-static-analysis.py David Malcolm
2017-08-04 21:37 ` [PATCH 04/22] Add firehose.h/cc David Malcolm
2017-08-04 21:37 ` [PATCH 15/22] Add checkers/clang_analyzer.py David Malcolm
2017-08-04 21:37 ` [PATCH 11/22] Add checkers/test-sources David Malcolm
2017-08-04 21:38 ` [PATCH 14/22] Add checkers/always_fails.py David Malcolm
2017-08-04 21:38 ` [PATCH 21/22] Add checkers/Makefile David Malcolm
2017-08-04 21:38 ` [PATCH 06/22] Makefile.in: hack in -lpthread David Malcolm
2017-09-01 18:13 ` Jeff Law
2017-08-04 21:38 ` [PATCH 13/22] Add checkers/checker.py David Malcolm
2017-08-04 21:38 ` [PATCH 12/22] Add -Wrun-analyzers= to common.opt, toplev.c, and invoke.texi David Malcolm
2017-08-04 21:39 ` [PATCH 18/22] Add checkers/flawfinder.py David Malcolm
2017-08-04 21:39 ` [PATCH 05/22] diagnostic.c/h: add support for external tools David Malcolm
2017-09-01 18:18 ` Jeff Law
2017-08-04 21:39 ` [PATCH 20/22] Add checkers/splint.py David Malcolm
2017-08-05 1:00 ` [PATCH 00/22] RFC: integrated 3rd-party static analysis support Eric Gallager
2017-08-08 0:23 ` David Malcolm
2017-08-06 21:21 ` Martin Sebor
2017-08-08 17:57 ` Richard Sandiford
2017-09-01 17:46 ` Jeff Law
2017-09-02 2:46 ` Trevor Saunders
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1501884293-9047-10-git-send-email-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).