diff options
author | Rob Landley <rob@landley.net> | 2008-10-24 23:19:38 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2008-10-24 23:19:38 -0500 |
commit | 839fb0b36ef91c8b69aea88f2f0258453e932b74 (patch) | |
tree | 44590a40e9da2f2d0935122c21b6160d1266aacc /toys | |
parent | bdf037ff5e1b933d624ac74c62c5c1eb14464737 (diff) | |
download | toybox-839fb0b36ef91c8b69aea88f2f0258453e932b74.tar.gz |
Tighten up chvt, save a few bytes.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/chvt.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/toys/chvt.c b/toys/chvt.c index 6504bff1..9afb059b 100644 --- a/toys/chvt.c +++ b/toys/chvt.c @@ -23,22 +23,17 @@ config CHVT #include "toys.h" -#define VT_ACTIVATE 0x5606 -#define VT_WAITACTIVE 0x5607 - /* Note: get_console_fb() will need to be moved into a seperate lib section */ int get_console_fd() { int fd; + char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc; - fd = open("/dev/console", O_RDWR); - if (fd >= 0) return fd; - - fd = open("/dev/vc/0", O_RDWR); - if (fd >= 0) return fd; - - fd = open("/dev/tty", O_RDWR); - if (fd >= 0) return fd; + cc = consoles; + while (*cc) { + fd = open(*cc++, O_RDWR); + if (fd >= 0) return fd; + } return -1; } @@ -47,15 +42,10 @@ void chvt_main(void) { int vtnum, fd; - - if(!*toys.optargs) return; - vtnum=atoi(*toys.optargs); fd=get_console_fd(); - if (fd < 0 || ioctl(fd,VT_ACTIVATE,vtnum) - || ioctl(fd,VT_WAITACTIVE,vtnum)) - { + // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h + if (fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum)) perror_exit(NULL); - } } |