From feae8b8f6840edbefe28aa81f472230c1f0ed599 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 5 May 2009 22:51:22 +0200 Subject: test/run_encoder: flush the encoder before exiting --- test/run_encoder.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/run_encoder.c b/test/run_encoder.c index faae9ecde..6b519d130 100644 --- a/test/run_encoder.c +++ b/test/run_encoder.c @@ -28,6 +28,16 @@ #include #include +static void +encoder_to_stdout(struct encoder *encoder) +{ + size_t length; + static char buffer[32768]; + + while ((length = encoder_read(encoder, buffer, sizeof(buffer))) > 0) + write(1, buffer, length); +} + int main(int argc, char **argv) { GError *error = NULL; @@ -98,8 +108,6 @@ int main(int argc, char **argv) /* do it */ while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { - size_t length; - ret = encoder_write(encoder, buffer, nbytes, &error); if (!ret) { g_printerr("encoder_write() failed: %s\n", @@ -108,8 +116,16 @@ int main(int argc, char **argv) return 1; } - length = encoder_read(encoder, buffer, sizeof(buffer)); - if (length > 0) - write(1, buffer, length); + encoder_to_stdout(encoder); } + + ret = encoder_flush(encoder, &error); + if (!ret) { + g_printerr("encoder_flush() failed: %s\n", + error->message); + g_error_free(error); + return 1; + } + + encoder_to_stdout(encoder); } -- cgit v1.2.3