]> sigrok.org Git - libsigrok.git/blobdiff - src/output/output.c
output: Actually return a NULL-terminated array.
[libsigrok.git] / src / output / output.c
index 3e432c9f0c7b82458621ef70ab0da8fa16b38364..0dd1fe27f7e1cf6bf19f5674cae2546526a82906 100644 (file)
@@ -160,29 +160,41 @@ SR_API const struct sr_output_module *sr_output_find(char *id)
  *
  * @since 0.4.0
  */
-SR_API const struct sr_option *sr_output_options_get(const struct sr_output_module *o)
+SR_API const struct sr_option **sr_output_options_get(const struct sr_output_module *o)
 {
+       const struct sr_option *mod_opts, **opts;
+       int size, i;
 
        if (!o || !o->options)
                return NULL;
 
-       return o->options();
+       mod_opts = o->options();
+
+       for (size = 1; mod_opts[size].id; size++)
+               ;
+       opts = g_malloc(size * sizeof(struct sr_option *));
+
+       for (i = 0; i < size; i++)
+               opts[i] = &mod_opts[i];
+       opts[i] = NULL;
+
+       return opts;
 }
 
 /**
  * After a call to sr_output_options_get(), this function cleans up all
- * resources allocated by that call.
+ * resources returned by that call.
  *
  * @since 0.4.0
  */
-SR_API void sr_output_options_free(const struct sr_output_module *o)
+SR_API void sr_output_options_free(const struct sr_option **opts)
 {
        struct sr_option *opt;
 
-       if (!o || !o->options)
+       if (!opts)
                return;
 
-       for (opt = o->options(); opt->id; opt++) {
+       for (opt = (struct sr_option *)opts[0]; opt; opt++) {
                if (opt->def) {
                        g_variant_unref(opt->def);
                        opt->def = NULL;
@@ -193,6 +205,7 @@ SR_API void sr_output_options_free(const struct sr_output_module *o)
                        opt->values = NULL;
                }
        }
+       g_free(opts);
 }
 
 /**