diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-14 08:41:44 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-14 08:41:44 +0100 |
| commit | 4a0bec23f06a4e119531fb8a62c07d346116c709 (patch) | |
| tree | 4e15bd8037011383f0f6dccaa4c7e60ad5a4c582 /src/blind-split.c | |
| parent | Update todo (diff) | |
| download | blind-4a0bec23f06a4e119531fb8a62c07d346116c709.tar.gz blind-4a0bec23f06a4e119531fb8a62c07d346116c709.tar.bz2 blind-4a0bec23f06a4e119531fb8a62c07d346116c709.tar.xz | |
Fix blind-split and add example
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-split.c')
| -rw-r--r-- | src/blind-split.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/blind-split.c b/src/blind-split.c index ff6ce38..6b06da5 100644 --- a/src/blind-split.c +++ b/src/blind-split.c @@ -26,7 +26,7 @@ main(int argc, char *argv[]) einit_stream(&stream); 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) + if (stream.frames > (size_t)SSIZE_MAX / frame_size) eprintf("%s: video is too large\n", stream.file); parts = (size_t)argc / 2; @@ -55,12 +55,17 @@ main(int argc, char *argv[]) efflush(fp, argv[i * 2]); for (end = ends[i] * frame_size; ptr < end; ptr += n) { - if (stream.ptr == sizeof(stream.buf)) - n = stream.ptr < end - ptr ? stream.ptr : end - ptr; - else if (!(n = eread_stream(&stream, end - ptr))) + n = end - ptr; + if (stream.ptr) { + n = stream.ptr < n ? stream.ptr : n; + ewriteall(fd, stream.buf, n, argv[i * 2]); + memmove(stream.buf, stream.buf + n, stream.ptr -= n); + } else if ((n = eread_stream(&stream, n))) { + ewriteall(fd, stream.buf, n, argv[i * 2]); + stream.ptr = 0; + } else { 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)) |
