]> sigrok.org Git - libsigrok.git/blobdiff - output/text/text.c
ascii: fix for big-endian architectures.
[libsigrok.git] / output / text / text.c
index 3ca9f4f505c98b44374c87410310967f9a5ae314..674fa8867e3eb492263b6131c86da5e2a4cc627d 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
- * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
+ * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
  * Copyright (C) 2011 HÃ¥vard Espeland <gus@ping.uio.no>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -79,7 +79,8 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
        struct context *ctx;
        struct sr_probe *probe;
        GSList *l;
-       uint64_t *samplerate;
+       GVariant *gvar;
+       uint64_t samplerate;
        int num_probes, ret;
        char *samplerate_s;
 
@@ -124,12 +125,13 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
        snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING);
        num_probes = g_slist_length(o->sdi->probes);
        if (o->sdi->driver || sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
-               ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
-                               (const void **)&samplerate, o->sdi);
-               if (ret != SR_OK)
+               if ((ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar,
+                               o->sdi)) != SR_OK)
                        goto err;
-               if (!(samplerate_s = sr_samplerate_string(*samplerate))) {
+               samplerate = g_variant_get_uint64(gvar);
+               if (!(samplerate_s = sr_samplerate_string(samplerate))) {
                        ret = SR_ERR;
+                       g_variant_unref(gvar);
                        goto err;
                }
                snprintf(ctx->header + strlen(ctx->header),
@@ -137,6 +139,7 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
                         "Acquisition with %d/%d probes at %s\n",
                         ctx->num_enabled_probes, num_probes, samplerate_s);
                g_free(samplerate_s);
+               g_variant_unref(gvar);
        }
 
        ctx->linebuf_len = ctx->samples_per_line * 2 + 4;
@@ -151,6 +154,12 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
                ret = SR_ERR_MALLOC;
        }
 
+       if (mode == MODE_ASCII &&
+                       !(ctx->prevsample = g_try_malloc0(num_probes / 8))) {
+               sr_err("%s: ctx->prevsample malloc failed", __func__);
+               ret = SR_ERR_MALLOC;
+       }
+
 err:
        if (ret != SR_OK) {
                g_free(ctx->header);