static int OpenAdc()

in CodeSnippets/Peripherals/ADC/AdvancedFunctions/advanced_functions.c [117:136]


static int OpenAdc(ADC_ControllerId adcControllerId)
{
    // Format the ADC path.
    char path[32];
    int len = snprintf(path, sizeof(path), "%s%u", adcPath, adcControllerId);
    if (len < 0 || len >= sizeof(path)) {
        Log_Debug("ERROR: Cannot format ADC path to buffer.\n");
        return -1;
    }

    int fd = open(path, O_RDWR | O_CLOEXEC, 0);
    if (fd == -1) {
        if (errno == ENOENT) {
            Log_Debug("ERROR: open failed with error: %s (%d)\n", strerror(errno), errno);
        }
        return -1;
    }

    return fd;
}