afh/audioc: Explicitly mark STDOUT as blocking.
authorAndre Noll <maan@systemlinux.org>
Tue, 6 Dec 2011 17:17:57 +0000 (18:17 +0100)
committerAndre Noll <maan@systemlinux.org>
Wed, 4 Jan 2012 14:44:25 +0000 (15:44 +0100)
STDOUT_FILENO is usually set to blocking mode, but as we rely on this,
it is safer to clear the nonblock flag explicitly.

afh.c
audioc.c

diff --git a/afh.c b/afh.c
index 66c4d1c..4b4cc78 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -115,6 +115,10 @@ static int cat_file(struct afh_info *afhi, int audio_format_id,
                return -ERRNO_TO_PARA_ERROR(EINVAL);
        if (!afhi->chunks_total)
                return 1;
+       /* eliminate the possibility of short writes */
+       ret = mark_fd_blocking(STDOUT_FILENO);
+       if (ret < 0)
+               return ret;
        if (first_chunk > 0 && !conf.no_header_given) {
                afh_get_header(afhi, audio_format_id, audio_file_data, audio_file_size,
                        &header, &size);
index e12d6e9..52c2bd3 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -332,6 +332,9 @@ int main(int argc, char *argv[])
                goto out;
        bufsize = conf.bufsize_arg;
        buf = para_malloc(bufsize);
+       ret = mark_fd_blocking(STDOUT_FILENO);
+       if (ret < 0)
+               goto out;
        do {
                size_t n = ret = recv_bin_buffer(fd, buf, bufsize);
                if (ret <= 0)