com_lsblob: Print an error message if no blob matched.
[paraslash.git] / oss_write.c
index 687275f366f35fd914204c6c56722984a1ee68cd..d583c2338bb1dc0dc96d274d49824d45a3b75c6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2009-2011 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -9,7 +9,6 @@
 #include <regex.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
-#include <dirent.h>
 #include <sys/soundcard.h>
 #include <stdbool.h>
 
@@ -54,7 +53,7 @@ static void oss_pre_select(struct sched *s, struct task *t)
 
        if (ret == 0)
                return;
-       if (ret < 0 || powd->fd < 0)
+       if (ret < 0 || !powd)
                return sched_min_delay(s);
        para_fd_set(powd->fd, &s->wfds, &s->max_fileno);
 }
@@ -63,8 +62,9 @@ static void oss_close(struct writer_node *wn)
 {
        struct private_oss_write_data *powd = wn->private_data;
 
-       if (powd->fd >= 0)
-               close(powd->fd);
+       if (!powd)
+               return;
+       close(powd->fd);
        free(powd);
 }
 
@@ -85,12 +85,12 @@ static int oss_init(struct writer_node *wn, unsigned sample_rate,
        int ret, format;
        unsigned ch, rate;
        struct oss_write_args_info *conf = wn->conf;
-       struct private_oss_write_data *powd = wn->private_data;
+       struct private_oss_write_data *powd = para_calloc(sizeof(*powd));
 
        PARA_INFO_LOG("opening %s\n", conf->device_arg);
        ret = para_open(conf->device_arg, O_WRONLY, 0);
        if (ret < 0)
-               return ret;
+               goto err_free;
        powd->fd = ret;
        ret = mark_fd_nonblocking(powd->fd);
        if (ret < 0)
@@ -147,10 +147,12 @@ static int oss_init(struct writer_node *wn, unsigned sample_rate,
                        sample_rate);
        }
        wn->min_iqs = powd->bytes_per_frame;
+       wn->private_data = powd;
        return 1;
 err:
        close(powd->fd);
-       powd->fd = -1;
+err_free:
+       free(powd);
        return ret;
 }
 
@@ -168,7 +170,7 @@ static void oss_post_select(__a_unused struct sched *s,
                goto out;
        if (ret == 0)
                return;
-       if (powd->fd < 0) {
+       if (!powd) {
                int32_t rate, ch, format;
                get_btr_sample_rate(btrn, &rate);
                get_btr_channels(btrn, &ch);
@@ -182,7 +184,7 @@ static void oss_post_select(__a_unused struct sched *s,
        bytes = btr_next_buffer(btrn, &data);
        frames = bytes / powd->bytes_per_frame;
        if (!frames) { /* eof and less than a single frame available */
-               ret = -E_OSS_EOF;
+               ret = -E_WRITE_COMMON_EOF;
                goto out;
        }
        ret = 0;
@@ -199,14 +201,6 @@ out:
                btr_remove_node(btrn);
 }
 
-static void oss_open(struct writer_node *wn)
-{
-       struct private_oss_write_data *powd = para_calloc(sizeof(*powd));
-
-       powd->fd = -1;
-       wn->private_data = powd;
-}
-
 __malloc static void *oss_parse_config_or_die(const char *options)
 {
        struct oss_write_args_info *conf = para_calloc(sizeof(*conf));
@@ -233,7 +227,6 @@ void oss_write_init(struct writer *w)
        struct oss_write_args_info dummy;
 
        oss_cmdline_parser_init(&dummy);
-       w->open = oss_open;
        w->close = oss_close;
        w->pre_select = oss_pre_select;
        w->post_select = oss_post_select;