aboutsummaryrefslogtreecommitdiffstats
path: root/src/vu-repeat.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-01-11 09:11:51 +0100
committerMattias Andrée <maandree@kth.se>2017-01-11 09:11:51 +0100
commitb7a82c980fe7e0c1f9029b55be97422428d65d5a (patch)
tree67bedc856eb1f72a2daa8ef8347b904269b06df5 /src/vu-repeat.c
parentvu-crop: add -t (diff)
downloadblind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.gz
blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.bz2
blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.xz
Clean up code
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/vu-repeat.c')
-rw-r--r--src/vu-repeat.c50
1 files changed, 13 insertions, 37 deletions
diff --git a/src/vu-repeat.c b/src/vu-repeat.c
index 87eb3f9..0c0e510 100644
--- a/src/vu-repeat.c
+++ b/src/vu-repeat.c
@@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
-#include "arg.h"
#include "stream.h"
#include "util.h"
@@ -9,59 +8,40 @@
#include <string.h>
#include <unistd.h>
-static void
-usage(void)
-{
- eprintf("usage: %s (count | 'inf') file\n", argv0);
-}
+USAGE("(count | 'inf') file")
int
main(int argc, char *argv[])
{
struct stream stream;
- size_t count = 0, ptr, n, ptw;
+ size_t count = 0, ptr, n;
ssize_t r;
char buf[BUFSIZ];
int inf = 0;
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ ENOFLAGS(argc != 2);
- if (argc != 2)
- usage();
-
- if (!strcmp(argv[0], "inf")) {
+ 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);
- }
+ else
+ count = etozu_arg("the count", argv[0], 0, SIZE_MAX);
if (inf)
einf_check_fd(STDOUT_FILENO, "<stdout>");
stream.file = argv[1];
- stream.fd = open(stream.file, O_RDONLY);
- if (stream.fd < 0)
- eprintf("open %s:", stream.file);
+ stream.fd = eopen(stream.file, O_RDONLY);
einit_stream(&stream);
if (count > SIZE_MAX / stream.frames)
- eprintf("%s: video too long\n", stream.file);
+ eprintf("%s: video is too long\n", stream.file);
stream.frames *= count;
fprint_stream_head(stdout, &stream);
- fflush(stdout);
- if (ferror(stdout))
- eprintf("<stdout>:");
+ efflush(stdout, "<stdout>");
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)
- goto writeerr;
- ptw += (size_t)r;
- }
+ if (writeall(STDOUT_FILENO, stream.buf, stream.ptr))
+ goto writeerr;
for (ptr = 0;;) {
r = pread(stream.fd, buf, sizeof(buf), ptr);
if (r < 0)
@@ -69,12 +49,8 @@ main(int argc, char *argv[])
else if (r == 0)
break;
ptr += n = (size_t)r;
- for (ptw = 0; ptw < n;) {
- r = write(STDOUT_FILENO, buf + ptw, n - ptw);
- if (r < 0)
- goto writeerr;
- ptw += (size_t)r;
- }
+ if (writeall(STDOUT_FILENO, buf, n))
+ goto writeerr;
}
}