diff options
author | Elliott Hughes <enh@google.com> | 2019-06-22 11:22:17 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-06-24 19:50:03 -0500 |
commit | 96231a5a77dc1c3c0e84eb78e6dd7574505928eb (patch) | |
tree | ade7570da727a92b0fb48d597eaef411d165926d /toys/pending | |
parent | 85920266afd45a972d5e1b092b45de5d8d8496a5 (diff) | |
download | toybox-96231a5a77dc1c3c0e84eb78e6dd7574505928eb.tar.gz |
diff: fix diff of stdin for systems without /tmp.
xtempfile() alreay does the right thing, so switch to that.
Also use xsendfile() for the actual copying.
Fixes the cat tests on Android.
Diffstat (limited to 'toys/pending')
-rw-r--r-- | toys/pending/diff.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/toys/pending/diff.c b/toys/pending/diff.c index 4a528134..d865e8df 100644 --- a/toys/pending/diff.c +++ b/toys/pending/diff.c @@ -180,20 +180,13 @@ static void do_merge(struct candidate **K, int *k, int i, static FILE* read_stdin() { - char tmp_name[] = "/tmp/diffXXXXXX"; - int rd, wr, tmpfd = mkstemp(tmp_name); + char *tmp_name; + int tmpfd = xtempfile("stdin", &tmp_name); - if (tmpfd == -1) perror_exit("mkstemp"); unlink(tmp_name); + free(tmp_name); - while (1) { - rd = xread(STDIN_FILENO, toybuf, sizeof(toybuf)); - - if (!rd) break; - if (rd < 0) perror_exit("read error"); - wr = writeall(tmpfd, toybuf, rd); - if (wr < 0) perror_exit("write"); - } + xsendfile(0, tmpfd); return fdopen(tmpfd, "r"); } |