mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 14:25:03 +02:00
chore: chvt_str into chvt.c
This commit is contained in:
parent
a393cda7e1
commit
fe4a52ecfa
@ -14,5 +14,12 @@
|
|||||||
* @return int non-negative value on success
|
* @return int non-negative value on success
|
||||||
*/
|
*/
|
||||||
int chvt(int n);
|
int chvt(int n);
|
||||||
|
/**
|
||||||
|
* @brief change foreground virtual terminal to `str`
|
||||||
|
*
|
||||||
|
* @param str virtual terminal number (string)
|
||||||
|
* @return int non-negative value on success
|
||||||
|
*/
|
||||||
|
int chvt_str(char* str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
18
src/chvt.c
18
src/chvt.c
@ -1,10 +1,28 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <chvt.h>
|
#include <chvt.h>
|
||||||
|
|
||||||
static char *vterms[] = {"/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty",
|
static char *vterms[] = {"/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty",
|
||||||
"/dev/console"};
|
"/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) {
|
int chvt(int n) {
|
||||||
fprintf(stderr, "activating vt %d\n", n);
|
fprintf(stderr, "activating vt %d\n", n);
|
||||||
char c = 0;
|
char c = 0;
|
||||||
|
16
src/main.c
16
src/main.c
@ -1,5 +1,3 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -12,20 +10,6 @@
|
|||||||
#include <ui.h>
|
#include <ui.h>
|
||||||
#include <users.h>
|
#include <users.h>
|
||||||
|
|
||||||
int chvt_str(char *str) {
|
|
||||||
char *err;
|
|
||||||
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 main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
chvt_str(argv[1]);
|
chvt_str(argv[1]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user