From: Kevin Locke <kevin@kevinlocke.name>
To: ccan@lists.ozlabs.org
Subject: [PATCH v3 3/7] configurator: Print test source without cat
Date: Wed, 28 Sep 2016 18:44:44 -0600 [thread overview]
Message-ID: <fb76d96429516b23dde749e045ab4ecd5e1e12df.1475109043.git.kevin@kevinlocke.name> (raw)
In-Reply-To: <cover.1475109043.git.kevin@kevinlocke.name>
Windows does not provide cat. Instead, copy the test source to stdout
using the file stream to which it was written.
Changes since v1:
- Create fwrite_noeintr to avoid EINTR in fwrite without writing any
data.
- Handle short reads from fread. This can happen with non-conformant
libc or if EINTR occurs after reading some data.
- Handle short writes from fwrite. This can happen with non-conformant
libc or if EINTR occurs after writing some data.
Changes since v2:
- Revert fwrite_noeintr and short read/write changes.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
---
tools/configurator/configurator.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c
index a7cbfa5..73fdc95 100644
--- a/tools/configurator/configurator.c
+++ b/tools/configurator/configurator.c
@@ -407,6 +407,22 @@ static void c12r_errx(int eval, const char *fmt, ...)
exit(eval);
}
+static size_t fcopy(FILE *fsrc, FILE *fdst)
+{
+ char buffer[BUFSIZ];
+ size_t rsize, wsize;
+ size_t copied = 0;
+
+ while ((rsize = fread(buffer, 1, BUFSIZ, fsrc)) > 0) {
+ wsize = fwrite(buffer, 1, rsize, fdst);
+ copied += wsize;
+ if (wsize != rsize)
+ break;
+ }
+
+ return copied;
+}
+
static char *grab_stream(FILE *file)
{
size_t max, ret, size = 0;
@@ -530,7 +546,7 @@ static bool run_test(const char *cmd, struct test *test)
}
}
- outf = fopen(INPUT_FILE, "w");
+ outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w");
if (!outf)
c12r_err(1, "creating %s", INPUT_FILE);
@@ -561,11 +577,13 @@ static bool run_test(const char *cmd, struct test *test)
abort();
}
- fclose(outf);
- if (verbose > 1)
- if (system("cat " INPUT_FILE) == -1)
- ;
+ if (verbose > 1) {
+ fseek(outf, 0, SEEK_SET);
+ fcopy(outf, stdout);
+ }
+
+ fclose(outf);
newcmd = strdup(cmd);
--
2.9.3
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan
next prev parent reply other threads:[~2016-09-29 0:44 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-19 0:51 [PATCH 0/9] configurator: Support for Windows and MSVC Kevin Locke
2016-09-19 0:51 ` [PATCH 1/9] configurator: Replace unlink with remove Kevin Locke
2016-09-20 4:50 ` David Gibson
2016-09-19 0:51 ` [PATCH 2/9] configurator: Reimplement run using popen Kevin Locke
2016-09-20 5:00 ` David Gibson
2016-09-20 6:22 ` Kevin Locke
2016-09-20 13:28 ` David Gibson
2016-09-19 0:52 ` [PATCH 3/9] configurator: Inline err.h functions from musl libc Kevin Locke
2016-09-20 5:03 ` David Gibson
2016-09-27 6:11 ` Rusty Russell
2016-09-19 0:52 ` [PATCH 4/9] configurator: Use native directory separator Kevin Locke
2016-09-20 5:04 ` David Gibson
2016-09-19 0:52 ` [PATCH 5/9] configurator: Mark non-Windows tests MAY_NOT_COMPILE Kevin Locke
2016-09-20 5:06 ` David Gibson
2016-09-19 0:52 ` [PATCH 6/9] configurator: Print test source without cat Kevin Locke
2016-09-20 5:09 ` David Gibson
2016-09-19 0:52 ` [PATCH 7/9] configurator: Fix compiler warning with compare Kevin Locke
2016-09-20 5:09 ` David Gibson
2016-09-19 0:52 ` [PATCH 8/9] configurator: Pass output cflag to configurator Kevin Locke
2016-09-20 5:23 ` David Gibson
2016-09-20 6:22 ` Kevin Locke
2016-09-20 13:32 ` David Gibson
2016-09-19 0:52 ` [PATCH 9/9] configurator: DEFAULT_{COMPILER, FLAGS} for MSVC Kevin Locke
2016-09-20 4:48 ` [PATCH 0/9] configurator: Support for Windows and MSVC David Gibson
2016-09-20 6:21 ` Kevin Locke
2016-09-20 12:25 ` David Gibson
2016-09-20 14:16 ` Daniel Burke
2016-09-22 2:00 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 00/13] " Kevin Locke
2016-09-23 3:33 ` [PATCH v2 01/13] configurator: Replace unlink with remove Kevin Locke
2016-09-27 4:50 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 02/13] configurator: Reimplement run using popen Kevin Locke
2016-09-27 4:52 ` David Gibson
2016-09-28 5:29 ` [PATCH v3 2/13] " Kevin Locke
2016-09-23 3:33 ` [PATCH v2 03/13] configurator: Inline err.h functions from musl libc Kevin Locke
2016-09-27 5:01 ` David Gibson
2016-09-28 5:35 ` [PATCH v3 3/13] configurator: Inline err.h functions Kevin Locke
2016-09-23 3:33 ` [PATCH v2 04/13] configurator: Use native directory separator Kevin Locke
2016-09-27 5:05 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 05/13] configurator: Mark non-Windows tests MAY_NOT_COMPILE Kevin Locke
2016-09-27 5:05 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 06/13] configurator: Print test source without cat Kevin Locke
2016-09-27 5:06 ` David Gibson
2016-09-28 5:38 ` Kevin Locke
2016-09-23 3:33 ` [PATCH v2 07/13] configurator: Fix compiler warning with compare Kevin Locke
2016-09-27 5:09 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 08/13] configurator: Add output cflag option and macro Kevin Locke
2016-09-27 5:17 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 09/13] configurator: DEFAULT_{COMPILER, FLAGS} for MSVC Kevin Locke
2016-09-27 5:17 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 10/13] configurator: Fix warning in HAVE_FOR_LOOP_DECLARATION Kevin Locke
2016-09-27 5:10 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 11/13] configurator: Return pointer difference as ptrdiff_t Kevin Locke
2016-09-27 5:10 ` David Gibson
2016-09-23 3:33 ` [PATCH v2 12/13] Makefile: Define CFLAGS_FORCE_C_SOURCE macro Kevin Locke
2016-09-27 5:18 ` David Gibson
2016-09-27 6:18 ` Rusty Russell
2016-09-28 2:01 ` David Gibson
2016-10-26 2:49 ` Rusty Russell
2016-09-23 3:33 ` [PATCH v2 13/13] Add appveyor.yml Kevin Locke
2016-09-27 5:20 ` David Gibson
2016-09-28 6:01 ` [PATCH v3 " Kevin Locke
2016-09-27 5:23 ` [PATCH v2 00/13] configurator: Support for Windows and MSVC David Gibson
2016-09-27 6:20 ` Rusty Russell
2016-09-28 6:32 ` Kevin Locke
2016-09-28 6:28 ` Kevin Locke
2016-09-29 0:21 ` David Gibson
2016-09-29 0:44 ` [PATCH v3 0/7] " Kevin Locke
2016-09-29 0:44 ` [PATCH v3 1/7] configurator: Reimplement run using popen Kevin Locke
2016-09-29 0:44 ` [PATCH v3 2/7] configurator: Inline err.h functions Kevin Locke
2016-09-29 0:44 ` Kevin Locke [this message]
2016-09-29 0:44 ` [PATCH v3 4/7] configurator: Add output cflag option and macro Kevin Locke
2016-09-29 0:44 ` [PATCH v3 5/7] configurator: DEFAULT_{COMPILER, FLAGS} for MSVC Kevin Locke
2016-09-29 0:44 ` [PATCH v3 6/7] Makefile: Define CFLAGS_FORCE_C_SOURCE macro Kevin Locke
2016-09-29 0:44 ` [PATCH v3 7/7] Add appveyor.yml Kevin Locke
2016-09-30 15:08 ` [PATCH v3 0/7] configurator: Support for Windows and MSVC David Gibson
2016-10-03 3:14 ` Kevin Locke
2016-12-02 20:23 ` AppVeyor custom Git URL support (was Re: [PATCH v3 0/7] configurator: Support for Windows and MSVC) Kevin Locke
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=fb76d96429516b23dde749e045ab4ecd5e1e12df.1475109043.git.kevin@kevinlocke.name \
--to=kevin@kevinlocke.name \
--cc=ccan@lists.ozlabs.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 NNTP newsgroup(s).