This incorporates Posix math support into ash. The Posix math support
[oweals/busybox.git] / deallocvt.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
4  * Renamed deallocvt.
5  */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/ioctl.h>
11 #include "busybox.h"
12
13 /* From <linux/vt.h> */
14 static const int VT_DISALLOCATE = 0x5608;  /* free memory associated to vt */
15
16 int deallocvt_main(int argc, char *argv[])
17 {
18         int fd, num, i;
19
20         //if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
21         if (argc > 2)
22                 show_usage();
23
24         fd = get_console_fd("/dev/console");
25
26         if (argc == 1) {
27                 /* deallocate all unused consoles */
28                 if (ioctl(fd, VT_DISALLOCATE, 0))
29                         perror_msg_and_die("VT_DISALLOCATE");
30         } else {
31                 for (i = 1; i < argc; i++) {
32                         num = atoi(argv[i]);
33                         if (num == 0)
34                                 error_msg("0: illegal VT number");
35                         else if (num == 1)
36                                 error_msg("VT 1 cannot be deallocated");
37                         else if (ioctl(fd, VT_DISALLOCATE, num))
38                                 perror_msg_and_die("VT_DISALLOCATE");
39                 }
40         }
41
42         return EXIT_SUCCESS;
43 }