diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-15 17:15:47 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-15 17:15:47 +0100 |
| commit | d6c07e7fa021e13b5b9914cb15f13c711ecd387d (patch) | |
| tree | 75fd767b2078a786c6bdb6729c45a63fd3b81979 /src | |
| parent | blind-config: fix -j (diff) | |
| download | blind-d6c07e7fa021e13b5b9914cb15f13c711ecd387d.tar.gz blind-d6c07e7fa021e13b5b9914cb15f13c711ecd387d.tar.bz2 blind-d6c07e7fa021e13b5b9914cb15f13c711ecd387d.tar.xz | |
Use macros to write the head
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | src/blind-concat.c | 7 | ||||
| -rw-r--r-- | src/blind-from-image.c | 2 | ||||
| -rw-r--r-- | src/blind-from-text.c | 2 | ||||
| -rw-r--r-- | src/blind-from-video.c | 4 | ||||
| -rw-r--r-- | src/blind-rewrite-head.c | 3 | ||||
| -rw-r--r-- | src/stream.c | 3 | ||||
| -rw-r--r-- | src/stream.h | 12 |
7 files changed, 20 insertions, 13 deletions
diff --git a/src/blind-concat.c b/src/blind-concat.c index bea127a..f6fe504 100644 --- a/src/blind-concat.c +++ b/src/blind-concat.c @@ -80,9 +80,7 @@ concat_to_file(int argc, char *argv[], char *output_file) close(stream.fd); } - sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", - stream.frames, stream.width, stream.height, stream.pixfmt, 0, &headlen); - + SPRINTF_HEAD_ZN(head, stream.frames, stream.width, stream.height, stream.pixfmt, &headlen); ewriteall(fd, head, (size_t)headlen, output_file); data = mmap(0, size + (size_t)headlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); @@ -131,8 +129,7 @@ concat_to_file_parallel(int argc, char *argv[], char *output_file, size_t jobs) frames += streams[i].frames; } - sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", - frames, streams->width, streams->height, streams->pixfmt, 0, &headlen); + SPRINTF_HEAD_ZN(head, frames, streams->width, streams->height, streams->pixfmt, &headlen); echeck_frame_size(streams->width, streams->height, streams->pixel_size, 0, output_file); frame_size = streams->width * streams->height * streams->pixel_size; diff --git a/src/blind-from-image.c b/src/blind-from-image.c index 7040038..0a3f767 100644 --- a/src/blind-from-image.c +++ b/src/blind-from-image.c @@ -254,7 +254,7 @@ after_fork: eprintf("%s\n", conv_fail_msg); if (!headless) { - printf("1 %s %s xyza\n%cuivf", width, height, 0); + FPRINTF_HEAD(stdout, 1, width, height, "xyza"); efflush(stdout, "<stdout>"); } diff --git a/src/blind-from-text.c b/src/blind-from-text.c index 68ea869..6717c99 100644 --- a/src/blind-from-text.c +++ b/src/blind-from-text.c @@ -47,7 +47,7 @@ main(int argc, char *argv[]) eprintf("<stdin>: no input\n"); } if (len && line[len - 1] == '\n') - line[--len] = '\n'; + line[--len] = '\0'; if ((size_t)len + 6 > sizeof(stream.buf)) eprintf("<stdin>: head is too long\n"); stream.fd = -1; diff --git a/src/blind-from-video.c b/src/blind-from-video.c index 178ab17..f164195 100644 --- a/src/blind-from-video.c +++ b/src/blind-from-video.c @@ -258,7 +258,7 @@ main(int argc, char *argv[]) } if (skip_length) { - sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", frames, width, height, "xyza", 0, &headlen); + SPRINTF_HEAD_ZN(head, frames, width, height, "xyza", &headlen); ewriteall(outfd, head, (size_t)headlen, outfile); } @@ -273,7 +273,7 @@ main(int argc, char *argv[]) frames = length / frame_size; if (!skip_length) { - sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", frames, width, height, "xyza", 0, &headlen); + SPRINTF_HEAD_ZN(head, frames, width, height, "xyza", &headlen); ewriteall(outfd, head, (size_t)headlen, outfile); data = mmap(0, length + (size_t)headlen, PROT_READ | PROT_WRITE, MAP_SHARED, outfd, 0); memmove(data + headlen, data, length); diff --git a/src/blind-rewrite-head.c b/src/blind-rewrite-head.c index 1de8a29..9111485 100644 --- a/src/blind-rewrite-head.c +++ b/src/blind-rewrite-head.c @@ -38,8 +38,7 @@ rewrite(struct stream *stream, int frames_auto) else if (stream->frames != frame_count) eprintf("%s: frame count mismatch\n", stream->file); - sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", - stream->frames, stream->width, stream->height, stream->pixfmt, 0, &headlen); + SPRINTF_HEAD_ZN(head, stream->frames, stream->width, stream->height, stream->pixfmt, &headlen); length = stream->frames * frame_size; if (length > (size_t)SSIZE_MAX || (size_t)headlen > (size_t)SSIZE_MAX - length) diff --git a/src/stream.c b/src/stream.c index a6e9692..2ad30ed 100644 --- a/src/stream.c +++ b/src/stream.c @@ -113,8 +113,7 @@ enset_pixel_size(int status, struct stream *stream) void fprint_stream_head(FILE *fp, struct stream *stream) { - fprintf(fp, "%zu %zu %zu %s\n%cuivf", - stream->frames, stream->width, stream->height, stream->pixfmt, 0); + FPRINTF_HEAD(fp, stream->frames, stream->width, stream->height, stream->pixfmt); } diff --git a/src/stream.h b/src/stream.h index 027db4a..53b7113 100644 --- a/src/stream.h +++ b/src/stream.h @@ -4,6 +4,18 @@ #define STREAM_HEAD_MAX (3 * 3 * sizeof(size_t) + sizeof(((struct stream *)0)->pixfmt) + 10) +#define SPRINTF_HEAD_ZN(BUF, FRAMES, WIDTH, HEIGHT, PIXFMT, LENP)\ + sprintf(BUF, "%zu %zu %zu %s\n%cuivf%zn",\ + FRAMES, WIDTH, HEIGHT, PIXFMT, 0, LENP) + +#define SPRINTF_HEAD(BUF, FRAMES, WIDTH, HEIGHT, PIXFMT)\ + sprintf(BUF, "%zu %zu %zu %s\n%cuivf",\ + FRAMES, WIDTH, HEIGHT, PIXFMT, 0) + +#define FPRINTF_HEAD(FP, FRAMES, WIDTH, HEIGHT, PIXFMT)\ + fprintf(fp, "%zu %zu %zu %s\n%cuivf",\ + FRAMES, WIDTH, HEIGHT, PIXFMT, 0) + #define einit_stream(...) eninit_stream(1, __VA_ARGS__) #define eset_pixel_size(...) enset_pixel_size(1, __VA_ARGS__) #define eread_stream(...) enread_stream(1, __VA_ARGS__) |
