Attribute Functions

ssize_t iio_attr_read_raw(const struct iio_attr *attr, char *dst, size_t len)

Read the content of the given attribute.

Parameters:
  • attr – A pointer to an iio_attr structure

  • dst – A pointer to the memory area where the read data will be stored

  • len – The available length of the memory area, in bytes

Returns:

On success, the number of bytes written to the buffer

Returns:

On error, a negative errno code is returned

ssize_t iio_attr_write_raw(const struct iio_attr *attr, const void *src, size_t len)

Set the value of the given attribute.

Parameters:
  • attr – A pointer to an iio_attr structure

  • src – A pointer to the data to be written

  • len – The number of bytes that should be written

Returns:

On success, the number of bytes written

Returns:

On error, a negative errno code is returned

const char *iio_attr_get_name(const struct iio_attr *attr)

Retrieve the name of an attribute.

Parameters:

attr – A pointer to an iio_attr structure

Returns:

A pointer to a static NULL-terminated string

const char *iio_attr_get_filename(const struct iio_attr *attr)

Retrieve the filename of an attribute.

Parameters:

attr – A pointer to an iio_attr structure

Returns:

A pointer to a static NULL-terminated string

const char *iio_attr_get_static_value(const struct iio_attr *attr)

Retrieve the static value of an attribute.

Parameters:

attr – A pointer to an iio_attr structure

Returns:

On success, a pointer to a static NULL-terminated string

Returns:

If the attribute does not have a static value, NULL is returned.

int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, double *max)

Extract the range from an attribute with suffix ‘_available’.

Parameters:
  • attr – A pointer to an iio_attr structure

  • min – Will be set with the range minimum value if string was successfully parsed

  • step – Will be set with the range step value if string was successfully parsed

  • max – Will be set with the range maximum value if string was successfully parsed

Returns:

On success, 0 is returned

Returns:

On error, a negative errno code is returned. For attributes without the ‘_available’ suffix, -ENXIO is returned. For attributes whose values do not follow the [min step max] format, -EOPNOTSUPP is returned.

int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *count)

Extract the list of elements from an attribute with suffix ‘_available’.

Parameters:
  • attr – A pointer to an iio_attr structure

  • list – A pointer to pointer to a dynamically allocated array of strings

  • count – Will be set with the number of words found only if the string was successfully parsed.

Returns:

On success, a dynamically allocated array of strings. It is the caller’s responsibility to free these newly allocated resources

Returns:

On success, 0 is returned

Returns:

On error, a negative errno code is returned. For attributes without the ‘_available’ suffix, -ENXIO is returned. For attributes whose values are in a range format, -EOPNOTSUPP is returned.

int iio_attr_get_available_buf(const struct iio_attr *attr, char *buf, size_t buflen, char **list, size_t *count)

A variant of iio_attr_get_available() that uses a caller-supplied, preallocated buffer. If the optional ‘list’ and ‘count’ parameters are provided, the buffer will be tokenized in place by replacing each delimiter with a null terminator (‘\0’). As a result, each element in ‘list’ will point to the start of a substring in the buffer, representing one of the available values. For instance, ‘list[0]’ points to the first value, ‘list[1]’ to the second, and so forth.

Parameters:
  • attr – A pointer to an iio_attr structure

  • buf – A buffer where the available data will be stored

  • buflen – The available length of the buffer, in bytes

  • list – Optional output array of char* pointers. Each element points to a token within the provided buffer and must not be freed, as the data is part of the buffer itself.

  • count – On input: should contain the size of the list[] array (number of available slots). On output: will contain the actual number of tokens (strings) found and stored in list[]. parsed. On fail, it will be set to 0

Returns:

On success, 0 is returned

Returns:

On error, a negative errno code is returned. For attributes without the ‘_available’ suffix, -ENXIO is returned. For attributes whose values are in a range format, -EOPNOTSUPP is returned. If not enough space is available in list[], the function returns -ENOSPC

void iio_available_list_free(char **list, size_t count)

Free the resources allocated only by iio_attr_get_available()

Parameters:
  • list – A pointer to a dynamically allocated array to be freed

  • count – The number of elements counted by iio_attr_get_available()

iio_attr_read(attr, ptr)

Read the content of the given attribute.

Parameters:
  • attr – A pointer to an iio_attr structure

  • ptr – A pointer to a variable where the value should be stored

Returns:

On success, 0 is returned

Returns:

On error, a negative errno code is returned

iio_attr_write(attr, val)

Set the value of the given attribute.

Parameters:
  • attr – A pointer to an iio_attr structure

  • val – The value to set the attribute to

Returns:

On success, the number of bytes written

Returns:

On error, a negative errno code is returned.

struct iio_attr
#include <iio.h>

Structure holding meta-data for an attribute.