Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* chvt.c - change virtual terminal for [k]freebsd
- Copyright (C) 2009 Werner Koch
- This file is free software; as a special exception the author gives
- unlimited permission to copy and/or distribute it, with or without
- modifications, as long as this notice is preserved.
- This file is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, to the extent permitted by law; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. */
- #include <sys/consio.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <err.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int
- main(int argc, char *argv[])
- {
- int fd, screen;
- if (argc < 1 || argc > 2) {
- fprintf(stderr, "usage: %s [VT number] [</dev/ttyvN]\n", argv[0]);
- return 1;
- }
- if ((fd = open("/dev/console", O_WRONLY, 0)) < 0)
- fd = fileno(stdin);
- if (argc == 1) {
- if (ioctl(fd, VT_GETACTIVE, &screen))
- err(errno, "VT_GETACTIVE failed");
- warnx("active VT = %d", screen);
- return 0;
- }
- sscanf(argv[1], "%d", &screen);
- if (screen < 1) {
- warnx("invalid VT = %d", screen);
- return 1;
- }
- if (ioctl(fd, VT_ACTIVATE, screen))
- err(errno, "VT_ACTIVATE failed");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement