From b7a82c980fe7e0c1f9029b55be97422428d65d5a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 11 Jan 2017 09:11:51 +0100 Subject: Clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/vu-reverse.c | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'src/vu-reverse.c') diff --git a/src/vu-reverse.c b/src/vu-reverse.c index bf96a60..5c978f2 100644 --- a/src/vu-reverse.c +++ b/src/vu-reverse.c @@ -1,47 +1,29 @@ /* See LICENSE file for copyright and license details. */ -#include "arg.h" #include "stream.h" #include "util.h" -#include #include -#include #include -static void -usage(void) -{ - eprintf("usage: %s file\n", argv0); -} +USAGE("file") int main(int argc, char *argv[]) { struct stream stream; - size_t frame_size, ptr, end, n, ptw; + size_t frame_size, ptr, end, n; ssize_t r; char buf[BUFSIZ]; - ARGBEGIN { - default: - usage(); - } ARGEND; - - if (argc != 1) - usage(); + ENOFLAGS(argc != 1); stream.file = argv[0]; - 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); fprint_stream_head(stdout, &stream); - fflush(stdout); - if (ferror(stdout)) - eprintf(":"); - if (stream.width > SIZE_MAX / stream.height) - eprintf("%s: video is too large\n", stream.file); - frame_size = stream.width * stream.height; + efflush(stdout, ""); + echeck_frame_size(stream.width, stream.height, stream.pixel_size, 0, stream.file); + frame_size = stream.width * stream.height * stream.pixel_size; if (stream.frames > SSIZE_MAX / frame_size) eprintf("%s: video is too large\n", stream.file); @@ -56,12 +38,7 @@ main(int argc, char *argv[]) else if (r == 0) eprintf("%s: file is shorter than expected\n", stream.file); ptr += n = (size_t)r; - for (ptw = 0; ptw < n;) { - r = write(STDOUT_FILENO, buf + ptw, n - ptw); - if (r < 0) - eprintf("write :"); - ptw += (size_t)r; - } + ewriteall(STDOUT_FILENO, buf, n, ""); } } -- cgit v1.2.3-70-g09d2