tools/iio/iio_utils.c
Source file repositories/reference/linux-study-clean/tools/iio/iio_utils.c
File Facts
- System
- Linux kernel
- Corpus path
tools/iio/iio_utils.c- Extension
.c- Size
- 21804 bytes
- Lines
- 989
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
string.hstdlib.hstdio.hstdint.hdirent.herrno.hctype.hiio_utils.h
Detected Declarations
function iioutils_break_up_namefunction iioutils_get_typefunction iioutils_get_param_floatfunction bsort_channel_array_by_indexfunction build_channel_arrayfunction calc_digitsfunction find_type_by_namefunction _write_sysfs_intfunction write_sysfs_intfunction write_sysfs_int_and_verifyfunction _write_sysfs_stringfunction write_sysfs_string_and_verifyfunction write_sysfs_stringfunction read_sysfs_posintfunction read_sysfs_floatfunction read_sysfs_string
Annotated Snippet
strlen(iio_direction[i]))) {
prefix = iio_direction[i];
break;
}
current = strdup(full_name + strlen(prefix) + 1);
if (!current)
return -ENOMEM;
working = strtok(current, "_\0");
if (!working) {
free(current);
return -EINVAL;
}
w = working;
r = working;
while (*r != '\0') {
if (!isdigit(*r)) {
*w = *r;
w++;
}
r++;
}
*w = '\0';
ret = asprintf(generic_name, "%s_%s", prefix, working);
free(current);
return (ret == -1) ? -ENOMEM : 0;
}
/**
* iioutils_get_type() - find and process _type attribute data
* @is_signed: output whether channel is signed
* @bytes: output how many bytes the channel storage occupies
* @bits_used: output number of valid bits of data
* @shift: output amount of bits to shift right data before applying bit mask
* @mask: output a bit mask for the raw data
* @be: output if data in big endian
* @device_dir: the IIO device directory
* @buffer_idx: the IIO buffer index
* @name: the channel name
* @generic_name: the channel type name
*
* Returns a value >= 0 on success, otherwise a negative error code.
**/
static int iioutils_get_type(unsigned int *is_signed, unsigned int *bytes,
unsigned int *bits_used, unsigned int *shift,
uint64_t *mask, unsigned int *be,
const char *device_dir, int buffer_idx,
const char *name, const char *generic_name)
{
FILE *sysfsfp;
int ret;
DIR *dp;
char *scan_el_dir, *builtname, *builtname_generic, *filename = 0;
char signchar, endianchar;
unsigned padint;
const struct dirent *ent;
ret = asprintf(&scan_el_dir, FORMAT_SCAN_ELEMENTS_DIR, device_dir, buffer_idx);
if (ret < 0)
return -ENOMEM;
ret = asprintf(&builtname, FORMAT_TYPE_FILE, name);
if (ret < 0) {
ret = -ENOMEM;
goto error_free_scan_el_dir;
}
ret = asprintf(&builtname_generic, FORMAT_TYPE_FILE, generic_name);
if (ret < 0) {
ret = -ENOMEM;
goto error_free_builtname;
}
dp = opendir(scan_el_dir);
if (!dp) {
ret = -errno;
goto error_free_builtname_generic;
}
ret = -ENOENT;
while (ent = readdir(dp), ent)
if ((strcmp(builtname, ent->d_name) == 0) ||
(strcmp(builtname_generic, ent->d_name) == 0)) {
ret = asprintf(&filename,
"%s/%s", scan_el_dir, ent->d_name);
if (ret < 0) {
Annotation
- Immediate include surface: `string.h`, `stdlib.h`, `stdio.h`, `stdint.h`, `dirent.h`, `errno.h`, `ctype.h`, `iio_utils.h`.
- Detected declarations: `function iioutils_break_up_name`, `function iioutils_get_type`, `function iioutils_get_param_float`, `function bsort_channel_array_by_index`, `function build_channel_array`, `function calc_digits`, `function find_type_by_name`, `function _write_sysfs_int`, `function write_sysfs_int`, `function write_sysfs_int_and_verify`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.