From 96231a5a77dc1c3c0e84eb78e6dd7574505928eb Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 22 Jun 2019 11:22:17 -0700 Subject: 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. --- toys/pending/diff.c | 15 ++++----------- 1 file 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"); } -- cgit v1.2.3