patch: shrink by Pascal Bellard <pascal.bellard AT ads-lu.com> (-80 bytes)
[oweals/busybox.git] / console-tools / setconsole.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  *  setconsole.c - redirect system console output
4  *
5  *  Copyright (C) 2004,2005  Enrik Berkhan <Enrik.Berkhan@inka.de>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8  */
9
10 #include "libbb.h"
11
12 #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
13 static const char setconsole_longopts[] ALIGN1 =
14         "reset\0" No_argument "r"
15         ;
16 #endif
17
18 #define OPT_SETCONS_RESET 1
19
20 int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
21 int setconsole_main(int argc, char **argv)
22 {
23         unsigned long flags;
24         const char *device = CURRENT_TTY;
25
26 #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
27         applet_long_options = setconsole_longopts;
28 #endif
29         flags = getopt32(argv, "r");
30
31         if (argc - optind > 1)
32                 bb_show_usage();
33
34         if (argc - optind == 1) {
35                 if (flags & OPT_SETCONS_RESET)
36                         bb_show_usage();
37                 device = argv[optind];
38         } else {
39                 if (flags & OPT_SETCONS_RESET)
40                         device = DEV_CONSOLE;
41         }
42
43         xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
44         return EXIT_SUCCESS;
45 }