Don't use strings directly in calls to usage(). This is in preparation
[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 #include "internal.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <fcntl.h>
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
13
14 /* From <linux/vt.h> */
15 #define VT_ACTIVATE     0x5606  /* make vt active */
16 #define VT_WAITACTIVE   0x5607  /* wait for vt active */
17
18 const char chvt_usage[] =
19         "chvt N\n"
20 #ifndef BB_FEATURE_TRIVIAL_HELP
21         "\nChanges the foreground virtual terminal to /dev/ttyN\n"
22 #endif
23         ;
24
25 int chvt_main(int argc, char **argv)
26 {
27         int fd, num;
28
29         if ((argc != 2) || (**(argv + 1) == '-'))
30                 usage (chvt_usage);
31         fd = get_console_fd("/dev/console");
32         num = atoi(argv[1]);
33         if (ioctl(fd, VT_ACTIVATE, num)) {
34                 perror("VT_ACTIVATE");
35                 exit(FALSE);
36         }
37         if (ioctl(fd, VT_WAITACTIVE, num)) {
38                 perror("VT_WAITACTIVE");
39                 exit(FALSE);
40         }
41         return(TRUE);
42 }
43
44
45 /*
46 Local Variables:
47 c-file-style: "linux"
48 c-basic-offset: 4
49 tab-width: 4
50 End:
51 */