| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "ioprio-util.h" |
| 4 |
#include "parse-util.h" |
| 5 |
#include "string-table.h" |
| 6 |
|
| 7 |
int ioprio_parse_priority(const char *s, int *ret) { |
| 8 |
int i, r; |
| 9 |
|
| 10 |
assert(s); |
| 11 |
assert(ret); |
| 12 |
|
| 13 |
r = safe_atoi(s, &i); |
| 14 |
if (r < 0) |
| 15 |
return r; |
| 16 |
|
| 17 |
if (!ioprio_priority_is_valid(i)) |
| 18 |
return -EINVAL; |
| 19 |
|
| 20 |
*ret = i; |
| 21 |
return 0; |
| 22 |
} |
| 23 |
|
| 24 |
static const char *const ioprio_class_table[] = { |
| 25 |
[IOPRIO_CLASS_NONE] = "none", |
| 26 |
[IOPRIO_CLASS_RT] = "realtime", |
| 27 |
[IOPRIO_CLASS_BE] = "best-effort", |
| 28 |
[IOPRIO_CLASS_IDLE] = "idle", |
| 29 |
}; |
| 30 |
|
| 31 |
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_NR_CLASSES-1); |