Major coreutils update.
[oweals/busybox.git] / console-tools / chvt.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * chvt.c - aeb - 940227 - Change virtual terminal
4  *
5  * busyboxed by Erik Andersen
6  */
7
8 /* getopt not needed */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <fcntl.h>
13 #include <sys/types.h>
14 #include <sys/ioctl.h>
15 #include "busybox.h"
16
17 /* From <linux/vt.h> */
18 static const int VT_ACTIVATE = 0x5606;  /* make vt active */
19 static const int VT_WAITACTIVE = 0x5607;  /* wait for vt active */
20
21 int chvt_main(int argc, char **argv)
22 {
23         int fd, num;
24
25         if ((argc != 2) || (**(argv + 1) == '-'))
26                 bb_show_usage();
27         fd = get_console_fd();
28         num = atoi(argv[1]);
29         if (ioctl(fd, VT_ACTIVATE, num))
30                 bb_perror_msg_and_die("VT_ACTIVATE");
31         if (ioctl(fd, VT_WAITACTIVE, num))
32                 bb_perror_msg_and_die("VT_WAITACTIVE");
33         return EXIT_SUCCESS;
34 }
35
36
37 /*
38 Local Variables:
39 c-file-style: "linux"
40 c-basic-offset: 4
41 tab-width: 4
42 End:
43 */