terminal-util: modernize vtnr_from_tty() a bit

This commit is contained in:
Lennart Poettering
2025-01-03 21:05:58 +01:00
parent 496639d02c
commit 57e55f93bb
3 changed files with 13 additions and 11 deletions
+8 -10
View File
@@ -777,26 +777,24 @@ bool tty_is_console(const char *tty) {
}
int vtnr_from_tty(const char *tty) {
int i, r;
int r;
assert(tty);
tty = skip_dev_prefix(tty);
if (!startswith(tty, "tty") )
const char *e = startswith(tty, "tty");
if (!e)
return -EINVAL;
if (!ascii_isdigit(tty[3]))
return -EINVAL;
r = safe_atoi(tty+3, &i);
unsigned u;
r = safe_atou(e, &u);
if (r < 0)
return r;
if (!vtnr_is_valid(u))
return -ERANGE;
if (i < 0 || i > 63)
return -EINVAL;
return i;
return (int) u;
}
int resolve_dev_console(char **ret) {