]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - afh.c
afh: Use write_all rather than plain write().
[paraslash.git] / afh.c
diff --git a/afh.c b/afh.c
index 37d71224ba5631cc24f79c194810c20f9d9eb95e..b76c72fdab6dbe445b1466de76c4f3dd58e33b92 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2011 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008-2012 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -7,7 +7,6 @@
 /** \file afh.c Paraslash's standalone audio format handler tool. */
 
 #include <regex.h>
-#include <dirent.h>
 #include <sys/time.h>
 
 #include "para.h"
@@ -116,12 +115,16 @@ 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);
                if (size > 0) {
                        PARA_INFO_LOG("writing header (%zu bytes)\n", size);
-                       ret = write(STDOUT_FILENO, header, size); /* FIXME */
+                       ret = write_all(STDOUT_FILENO, header, size);
                        afh_free_header(header, audio_format_id);
                        if (ret < 0)
                                return ret;
@@ -149,7 +152,7 @@ static int cat_file(struct afh_info *afhi, int audio_format_id,
                if (!size)
                        continue;
                PARA_INFO_LOG("writing chunk %lu\n", i);
-               ret = write_all(STDOUT_FILENO, buf, &size);
+               ret = write_all(STDOUT_FILENO, buf, size);
                if (ret < 0)
                        return ret;
        }