# HG changeset patch # User Rob Landley # Date 1381265888 18000 # Node ID bfe79fc710da564686338cd7e9266918e82cbfde # Parent 4f30bf2301962755ca6422765f985eb4dbe4faf0 Cleanup chvt diff -r 4f30bf230196 -r bfe79fc710da toys/other/chvt.c --- a/toys/other/chvt.c Tue Oct 08 12:25:02 2013 -0500 +++ b/toys/other/chvt.c Tue Oct 08 15:58:08 2013 -0500 @@ -19,29 +19,16 @@ #include "toys.h" -/* 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; - - cc = consoles; - while (*cc) { - fd = open(*cc++, O_RDWR); - if (fd >= 0) return fd; - } - - return -1; -} - void chvt_main(void) { int vtnum, fd; + char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc; vtnum=atoi(*toys.optargs); + for (cc = consoles; *cc; cc++) + if (-1 != (fd = open(*cc, O_RDWR))) break; - fd=get_console_fd(); // 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); + if (!*cc || fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum)) + perror_exit(0); }