From 33d7ef1e017b52a95d55887c05548b6207997b1c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 10 Jan 2017 04:30:02 +0100 Subject: vu-repeat: add option to repeat ad infinitum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/vu-repeat.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/vu-repeat.c') diff --git a/src/vu-repeat.c b/src/vu-repeat.c index aa5de9a..16f88cd 100644 --- a/src/vu-repeat.c +++ b/src/vu-repeat.c @@ -3,14 +3,16 @@ #include "stream.h" #include "util.h" +#include #include #include +#include #include static void usage(void) { - eprintf("usage: %s count file\n", argv0); + eprintf("usage: %s (count | 'inf') file\n", argv0); } int @@ -20,6 +22,7 @@ main(int argc, char *argv[]) size_t count = 0, ptr, n, ptw; ssize_t r; char buf[BUFSIZ]; + int inf = 0; ARGBEGIN { default: @@ -29,15 +32,18 @@ main(int argc, char *argv[]) if (argc != 2) usage(); - if (tozu(argv[0], 0, SIZE_MAX, &count)) + if (!strcmp(argv[0], "inf")) { + inf = 1; + } else if (tozu(argv[0], 0, SIZE_MAX, &count)) { eprintf("the count must be an integer in [0, %zu]\n", SIZE_MAX); + } stream.file = argv[1]; stream.fd = open(stream.file, O_RDONLY); if (stream.fd < 0) eprintf("open %s:", stream.file); einit_stream(&stream); - if (stream.frames > SIZE_MAX / count) + if (count > SIZE_MAX / stream.frames) eprintf("%s: video too long\n", stream.file); stream.frames *= count; fprint_stream_head(stdout, &stream); @@ -45,12 +51,12 @@ main(int argc, char *argv[]) if (ferror(stdout)) eprintf(":"); - while (count--) { + while (inf || count--) { posix_fadvise(stream.fd, 0, 0, POSIX_FADV_SEQUENTIAL); for (ptw = 0; ptw < stream.ptr;) { r = write(STDOUT_FILENO, stream.buf + ptw, stream.ptr - ptw); if (r < 0) - eprintf("write :"); + goto writeerr; ptw += (size_t)r; } for (ptr = 0;;) { @@ -63,7 +69,7 @@ main(int argc, char *argv[]) for (ptw = 0; ptw < n;) { r = write(STDOUT_FILENO, buf + ptw, n - ptw); if (r < 0) - eprintf("write :"); + goto writeerr; ptw += (size_t)r; } } @@ -71,4 +77,9 @@ main(int argc, char *argv[]) close(stream.fd); return 0; + +writeerr: + if (!inf || errno != EPIPE) + eprintf("write :"); + return 0; } -- cgit v1.2.3-70-g09d2