diff --git a/device.c b/device.c index 6d7f5c9a2..5ce68fa61 100644 --- a/device.c +++ b/device.c @@ -499,26 +499,38 @@ int iio_device_attr_read_double(const struct iio_device *dev, int iio_device_attr_write_longlong(const struct iio_device *dev, const char *attr, long long val) { + ssize_t ret; char buf[1024]; + snprintf(buf, sizeof(buf), "%lld", val); - return iio_device_attr_write(dev, attr, buf); + ret = iio_device_attr_write(dev, attr, buf); + + return ret < 0 ? ret : 0; } int iio_device_attr_write_double(const struct iio_device *dev, const char *attr, double val) { + ssize_t ret; char buf[1024]; + snprintf(buf, sizeof(buf), "%lf", val); - return iio_device_attr_write(dev, attr, buf); + ret = iio_device_attr_write(dev, attr, buf); + + return ret < 0 ? ret : 0; } int iio_device_attr_write_bool(const struct iio_device *dev, const char *attr, bool val) { + ssize_t ret; + if (val) - return iio_device_attr_write(dev, attr, "1"); + ret = iio_device_attr_write(dev, attr, "1"); else - return iio_device_attr_write(dev, attr, "0"); + ret = iio_device_attr_write(dev, attr, "0"); + + return ret < 0 ? ret : 0; } ssize_t iio_device_debug_attr_read(const struct iio_device *dev, @@ -608,26 +620,38 @@ int iio_device_debug_attr_read_double(const struct iio_device *dev, int iio_device_debug_attr_write_longlong(const struct iio_device *dev, const char *attr, long long val) { + ssize_t ret; + char buf[1024]; snprintf(buf, sizeof(buf), "%lld", val); - return iio_device_debug_attr_write(dev, attr, buf); + ret = iio_device_debug_attr_write(dev, attr, buf); + + return ret < 0 ? ret : 0; } int iio_device_debug_attr_write_double(const struct iio_device *dev, const char *attr, double val) { + ssize_t ret; + char buf[1024]; snprintf(buf, sizeof(buf), "%lf", val); - return iio_device_debug_attr_write(dev, attr, buf); + ret = iio_device_debug_attr_write(dev, attr, buf); + + return ret < 0 ? ret : 0; } int iio_device_debug_attr_write_bool(const struct iio_device *dev, const char *attr, bool val) { + ssize_t ret; + if (val) - return iio_device_debug_attr_write_raw(dev, attr, "1", 2); + ret = iio_device_debug_attr_write_raw(dev, attr, "1", 2); else - return iio_device_debug_attr_write_raw(dev, attr, "0", 2); + ret = iio_device_debug_attr_write_raw(dev, attr, "0", 2); + + return ret < 0 ? ret : 0; } int iio_device_identify_filename(const struct iio_device *dev, @@ -672,9 +696,13 @@ int iio_device_identify_filename(const struct iio_device *dev, int iio_device_reg_write(struct iio_device *dev, uint32_t address, uint32_t value) { + ssize_t ret; + char buf[1024]; snprintf(buf, sizeof(buf), "0x%x 0x%x", address, value); - return iio_device_debug_attr_write(dev, "direct_reg_access", buf); + ret = iio_device_debug_attr_write(dev, "direct_reg_access", buf); + + return ret < 0 ? ret : 0; } int iio_device_reg_read(struct iio_device *dev,