const char *command, const char *(*array)[], unsigned int n, int *result)
{
char *tmp;
- unsigned int i;
+ int idx;
if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK) {
g_free(tmp);
return SR_ERR;
}
- for (i = 0; i < n; i++) {
- if (!g_strcmp0(tmp, (*array)[i])) {
- *result = i;
- g_free(tmp);
- tmp = NULL;
- break;
- }
- }
-
- if (tmp) {
+ if ((idx = std_str_idx_s(tmp, *array, n)) < 0) {
g_free(tmp);
- return SR_ERR;
+ return SR_ERR_ARG;
}
+ *result = idx;
+
+ g_free(tmp);
+
return SR_OK;
}