aboutsummaryrefslogtreecommitdiffstats
path: root/src/vu-split.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-01-11 23:57:29 +0100
committerMattias Andrée <maandree@kth.se>2017-01-11 23:57:29 +0100
commit664c54ec31217e4939f12ee9a848ed4ac38561b6 (patch)
tree5a41b1b380f66a2be4a019ecaac62ab623be1c47 /src/vu-split.c
parentFix vu-repeat (diff)
downloadblind-664c54ec31217e4939f12ee9a848ed4ac38561b6.tar.gz
blind-664c54ec31217e4939f12ee9a848ed4ac38561b6.tar.bz2
blind-664c54ec31217e4939f12ee9a848ed4ac38561b6.tar.xz
Fix writeall + vu-split: reuse code
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/vu-split.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/vu-split.c b/src/vu-split.c
index e2e7968..b1ed398 100644
--- a/src/vu-split.c
+++ b/src/vu-split.c
@@ -15,10 +15,9 @@ int
main(int argc, char *argv[])
{
struct stream stream;
- size_t *ends, i, parts, ptr, end, frame_size, max, ptw, n;
+ size_t *ends, i, parts, ptr, end, frame_size, n;
FILE *fp;
int fd;
- ssize_t r;
ENOFLAGS(argc < 2 || argc % 2);
@@ -54,17 +53,12 @@ main(int argc, char *argv[])
efflush(fp, argv[i * 2]);
for (end = ends[i] * frame_size; ptr < end; ptr += n) {
- for (ptw = ptr; stream.ptr && ptw < end;) {
- max = end - ptw;
- max = max < stream.ptr ? max : stream.ptr;
- r = write(fd, stream.buf, max);
- if (r < 0)
- eprintf("write %s:\n", argv[i * 2]);
- memmove(stream.buf, stream.buf + r, stream.ptr - (size_t)r);
- }
- n = eread_stream(&stream, end - ptr);
- if (n == 0)
+ if (stream.ptr == sizeof(stream.buf))
+ n = stream.ptr < end - ptr ? stream.ptr : end - ptr;
+ else if (!(n = eread_stream(&stream, end - ptr)))
eprintf("%s: file is shorter than expected\n", stream.file);
+ ewriteall(STDOUT_FILENO, stream.buf, n, "<stdout>");
+ memmove(stream.buf, stream.buf + n, stream.ptr -= n);
}
if (fclose(fp))