gui: Check only once for invalid key maps.
[paraslash.git] / oss_write.c
index 687275f..df9608a 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.
  */
@@ -54,7 +54,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 +63,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 +86,13 @@ 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));
 
+       wn->private_data = 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)
@@ -150,7 +152,8 @@ static int oss_init(struct writer_node *wn, unsigned sample_rate,
        return 1;
 err:
        close(powd->fd);
-       powd->fd = -1;
+err_free:
+       free(powd);
        return ret;
 }
 
@@ -168,7 +171,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);
@@ -199,14 +202,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 +228,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;