X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afh.c;h=bffe63216e71627dde4b4b49b53c436388500444;hp=c5d7aec296a7a44b2fedfd2532ad838f89654e6c;hb=b55f405f8005821ffa369b929bc0b419da62683d;hpb=69a7e7aa11d8bf9b05d6431c57276befbc9b35a3 diff --git a/afh.c b/afh.c index c5d7aec2..bffe6321 100644 --- a/afh.c +++ b/afh.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2011 Andre Noll + * Copyright (C) 2008-2012 Andre Noll * * 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 -#include #include #include "para.h" @@ -16,6 +15,7 @@ #include "fd.h" #include "afh.h" #include "error.h" +#include "version.h" static struct afh_args_info conf; /** The list of all status items */ @@ -115,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; @@ -148,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; } @@ -183,8 +187,10 @@ int main(int argc, char **argv) int ret2; ret = mmap_full_file(conf.inputs[i], O_RDONLY, &audio_file_data, &audio_file_size, &fd); - if (ret < 0) + if (ret < 0) { + PARA_ERROR_LOG("failed to mmap \"%s\"\n", conf.inputs[i]); goto out; + } ret = compute_afhi(conf.inputs[i], audio_file_data, audio_file_size, fd, &afhi); if (ret < 0)