aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-repeat.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-04-09 23:46:17 +0200
committerMattias Andrée <maandree@kth.se>2017-04-09 23:46:17 +0200
commitdac6950d9e556d5521ad7913d27a6cf83e2a90a1 (patch)
treebb6a65d973337a0504117888d5534967cc51f479 /src/blind-repeat.c
parentClean up (diff)
downloadblind-dac6950d9e556d5521ad7913d27a6cf83e2a90a1.tar.gz
blind-dac6950d9e556d5521ad7913d27a6cf83e2a90a1.tar.bz2
blind-dac6950d9e556d5521ad7913d27a6cf83e2a90a1.tar.xz
Clean up
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-repeat.c')
-rw-r--r--src/blind-repeat.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/blind-repeat.c b/src/blind-repeat.c
index 29089c6..937536b 100644
--- a/src/blind-repeat.c
+++ b/src/blind-repeat.c
@@ -3,7 +3,6 @@
#include "util.h"
#include <errno.h>
-#include <fcntl.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
@@ -18,9 +17,7 @@ repeat_regular_file(char *file, size_t count, int inf)
size_t ptr;
ssize_t r;
- stream.file = file;
- stream.fd = eopen(stream.file, O_RDONLY);
- einit_stream(&stream);
+ eopen_stream(&stream, file);
if (count > SIZE_MAX / stream.frames)
eprintf("%s: video is too long\n", stream.file);
stream.frames *= count;
@@ -28,14 +25,9 @@ repeat_regular_file(char *file, size_t count, int inf)
efflush(stdout, "<stdout>");
while (inf || count--) {
-#if defined(POSIX_FADV_SEQUENTIAL)
- posix_fadvise(stream.fd, stream.headlen, 0, POSIX_FADV_SEQUENTIAL);
-#endif
+ fadvise_sequential(stream.fd, stream.headlen, 0);
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)
+ if (!(r = epread(stream.fd, buf, sizeof(buf), ptr, stream.file)))
break;
if (writeall(STDOUT_FILENO, buf, (size_t)r)) {
if (!inf || errno != EPIPE)
@@ -56,9 +48,7 @@ repeat_stdin(size_t count, int inf)
size_t ptr, size;
ssize_t r;
- stream.file = "<stdin>";
- stream.fd = STDIN_FILENO;
- einit_stream(&stream);
+ eopen_stream(&stream, NULL);
if (count > SIZE_MAX / stream.frames)
eprintf("%s: video is too long\n", stream.file);
stream.frames *= count;
@@ -66,17 +56,14 @@ repeat_stdin(size_t count, int inf)
efflush(stdout, "<stdout>");
ptr = stream.ptr;
- size = ptr < BUFSIZ ? BUFSIZ : ptr;
+ size = MAX(ptr, BUFSIZ);
buf = emalloc(size);
memcpy(buf, stream.buf, ptr);
for (;;) {
if (ptr == size)
buf = erealloc(buf, size <<= 1);
- r = read(STDIN_FILENO, buf + ptr, size - ptr);
- if (r < 0)
- eprintf("read <stdout>:");
- if (r == 0)
+ if (!(r = eread(STDIN_FILENO, buf + ptr, size - ptr, "<stdout>")))
break;
ptr += (size_t)r;
}