From 4674ec0e4b833ab0d0365225ba99228df14abe87 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 13 Jan 2017 09:05:08 +0100 Subject: Rename to blind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-repeat.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/blind-repeat.c (limited to 'src/blind-repeat.c') diff --git a/src/blind-repeat.c b/src/blind-repeat.c new file mode 100644 index 0000000..367d976 --- /dev/null +++ b/src/blind-repeat.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "stream.h" +#include "util.h" + +#include +#include +#include +#include +#include + +USAGE("(count | 'inf') file") + +int +main(int argc, char *argv[]) +{ + struct stream stream; + size_t count = 0, ptr; + ssize_t r; + char buf[BUFSIZ]; + int inf = 0; + + ENOFLAGS(argc != 2); + + if (!strcmp(argv[0], "inf")) + inf = 1; + else + count = etozu_arg("the count", argv[0], 0, SIZE_MAX); + + if (inf) + einf_check_fd(STDOUT_FILENO, ""); + + stream.file = argv[1]; + stream.fd = eopen(stream.file, O_RDONLY); + einit_stream(&stream); + if (count > SIZE_MAX / stream.frames) + eprintf("%s: video is too long\n", stream.file); + stream.frames *= count; + fprint_stream_head(stdout, &stream); + efflush(stdout, ""); + + while (inf || count--) { + posix_fadvise(stream.fd, stream.headlen, 0, POSIX_FADV_SEQUENTIAL); + for (ptr = stream.headlen;; ptr += (size_t)r) { + r = pread(stream.fd, buf, sizeof(buf), ptr); + if (r < 0) + eprintf("pread %s:", stream.file); + if (r == 0) + break; + if (writeall(STDOUT_FILENO, buf, (size_t)r)) { + if (!inf || errno != EPIPE) + eprintf("write :"); + return 0; + } + } + } + + close(stream.fd); + return 0; +} -- cgit v1.2.3-70-g09d2