]> git.tue.mpg.de Git - paraslash.git/commitdiff
check_wav: return error on premature end of file.
authorAndre <maan@p133.(none)>
Tue, 23 May 2006 18:47:31 +0000 (20:47 +0200)
committerAndre <maan@p133.(none)>
Tue, 23 May 2006 18:47:31 +0000 (20:47 +0200)
write.c

diff --git a/write.c b/write.c
index dffa5ecd65ca554de4f1ab60857901bb6033dfbe..7e6d47a56beb5e827ebbaa7d31cf2560f6b8f49f 100644 (file)
--- a/write.c
+++ b/write.c
@@ -32,6 +32,7 @@ INIT_WRITE_ERRLISTS;
 struct check_wav_task {
        char *buf;
        size_t *loaded;
+       int *eof;
        unsigned channels;
        unsigned sample_rate;
        struct task task;
@@ -53,8 +54,8 @@ static struct writer_node_group *wng;
 /**
  * test if audio buffer contains a valid wave header
  *
- * \return If not, return 0, otherwise, store number of channels and sample rate
- * in struct conf and return WAV_HEADER_LEN.
+ * \return If not, return -E_NO_WAV_HEADER, otherwise, return zero. If
+ * there is less than WAV_HEADER_LEN bytes awailable, return one.
  */
 static void check_wav_pre_select(struct sched *s, struct task *t)
 {
@@ -62,7 +63,7 @@ static void check_wav_pre_select(struct sched *s, struct task *t)
        unsigned char *a;
 
        if (*cwt->loaded < WAV_HEADER_LEN) {
-               t->ret = 1;
+               t->ret = *cwt->eof? -E_PREMATURE_END : 1;
                return;
        }
        a = (unsigned char*)cwt->buf;
@@ -149,7 +150,6 @@ static struct writer_node_group *check_args(void)
        ret = 1;
 out:
        if (ret > 0) {
-               wng->eof = &sit.eof;
                return wng;
        }
        free(wng);
@@ -163,6 +163,7 @@ static void idt_error_handler(struct task *t)
        unregister_task(t);
        wng->buf = sit.buf;
        wng->loaded = &sit.loaded;
+       wng->eof = &sit.eof;
        ret = wng_open(wng);
        if (ret < 0) {
                PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
@@ -225,6 +226,7 @@ int main(int argc, char *argv[])
        cwt.task.error_handler = cwt_error_handler;
        cwt.buf = sit.buf;
        cwt.loaded = &sit.loaded;
+       cwt.eof = &sit.eof;
        cwt.task.flags = PRE_EOF_IS_ERROR;
        register_task(&cwt.task);