chore: chvt_str into chvt.c

This commit is contained in:
2024-08-07 00:14:19 +02:00
parent a393cda7e1
commit fe4a52ecfa
3 changed files with 25 additions and 16 deletions

View File

@@ -1,10 +1,28 @@
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <chvt.h>
static char *vterms[] = {"/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty",
"/dev/console"};
int chvt_str(char *str) {
char *err;
errno = 0;
long i = strtol(str, &err, 10);
if (errno) {
perror("strol");
return -1;
}
// I'm not gonna elaborate on this....
if (i > INT_MAX || i < INT_MIN || *err)
return -1;
return chvt((int)i);
}
int chvt(int n) {
fprintf(stderr, "activating vt %d\n", n);
char c = 0;