in CodeSnippets/Peripherals/ADC/LinuxSysfsNodes/linux_sysfs_nodes.c [69:88]
static int OpenAdc(int adcChannel)
{
// Format the path for the channel.
char path[128];
int len = snprintf(path, sizeof(path), "%sin_voltage%d_raw", iioSysPath, adcChannel);
if (len < 0 || len >= sizeof(path)) {
fprintf(stderr, "ERROR: Cannot format ADC path to buffer.\n");
return -1;
}
int fd = open(path, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "ERROR: OpenAdc failed with error: %s (%d) for path %s.\n", strerror(errno),
errno,
path);
return -1;
}
return fd;
}