Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn when ignore return vals #386

Merged
merged 4 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

TARGETS := ad9361-iiostream ad9371-iiostream adrv9009-iiostream dummy-iiostream iio-monitor

CFLAGS = -Wall
CFLAGS = -Wall -DIIO_CHECK_RET

UNAME_S := $(shell uname -s)

Expand Down
23 changes: 19 additions & 4 deletions examples/dummy-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,22 @@ static bool has_repeat;
/* cleanup and exit */
static void shutdown()
{
int ret;

if (channels) { free(channels); }

printf("* Destroying buffers\n");
if (rxbuf) { iio_buffer_destroy(rxbuf); }

printf("* Disassociate trigger\n");
if (dev) { iio_device_set_trigger(dev, NULL); }
if (dev) {
ret = iio_device_set_trigger(dev, NULL);
if (ret < 0) {
char buf[256];
iio_strerror(-ret, buf, sizeof(buf));
fprintf(stderr, "%s (%d) while Disassociate trigger\n", buf, ret);
}
}

printf("* Destroying context\n");
if (ctx) { iio_context_destroy(ctx); }
Expand Down Expand Up @@ -333,11 +342,17 @@ int main (int argc, char **argv)
printf("\n");
break;

case SAMPLE_CALLBACK:
iio_buffer_foreach_sample(rxbuf, sample_cb, NULL);
case SAMPLE_CALLBACK: {
int ret;
ret = iio_buffer_foreach_sample(rxbuf, sample_cb, NULL);
if (ret < 0) {
char buf[256];
iio_strerror(-ret, buf, sizeof(buf));
fprintf(stderr, "%s (%d) while processing buffer\n", buf, ret);
}
printf("\n");
break;

}
case CHANNEL_READ_RAW:
case CHANNEL_READ:
for (int i = 0; i < channel_count; ++i) {
Expand Down
38 changes: 30 additions & 8 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,52 @@ static bool is_valid_channel(struct iio_channel *chn)
channel_has_attr(chn, "input"));
}

static void err_str(int ret)
{
char buf[256];
iio_strerror(-ret, buf, sizeof(buf));
fprintf(stderr, "Error during read: %s (%d)\n", buf, ret);
}

static double get_channel_value(struct iio_channel *chn)
{
char *old_locale;
char buf[1024];
double val;
int ret;

old_locale = strdup(setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "C");

if (channel_has_attr(chn, "input")) {
iio_channel_attr_read(chn, "input", buf, sizeof(buf));
val = strtod(buf, NULL);
ret = iio_channel_attr_read(chn, "input", buf, sizeof(buf));
if (ret < 0) {
err_str(ret);
val = 0;
} else
val = strtod(buf, NULL);
} else {
iio_channel_attr_read(chn, "raw", buf, sizeof(buf));
val = strtod(buf, NULL);
ret = iio_channel_attr_read(chn, "raw", buf, sizeof(buf));
if (ret < 0) {
err_str(ret);
val = 0;
} else
val = strtod(buf, NULL);

if (channel_has_attr(chn, "offset")) {
iio_channel_attr_read(chn, "offset", buf, sizeof(buf));
val += strtod(buf, NULL);
ret = iio_channel_attr_read(chn, "offset", buf, sizeof(buf));
if (ret < 0)
err_str(ret);
else
val += strtod(buf, NULL);
}

if (channel_has_attr(chn, "scale")) {
iio_channel_attr_read(chn, "scale", buf, sizeof(buf));
val *= strtod(buf, NULL);
ret = iio_channel_attr_read(chn, "scale", buf, sizeof(buf));
if (ret < 0)
err_str(ret);
else
val *= strtod(buf, NULL);
}
}

Expand Down
Loading