c
int safe_atoi(const char *str, int *result) {
    char *endptr;
    long temp = strtol(str, &endptr, 10);
    if (endptr != str && *endptr == '\0' && temp > 0 && temp <= INT_MAX) {
        *result = (int)temp;
        return 1;
    }
    return 0;
}

// Usage
if (safe_atoi(optarg, &horizSubSampling)) {
    // Conversion successful
} else {
    fprintf(stderr, "Error: Invalid horizontal subsampling value.\n");
    exit(1);
}
