4 Set and restore VC screen for vlock, the VT locking program for linux.
6 Copyright (C) 1997-1998 Juan Cespedes <cespedes@debian.org>
7 Copyright (C) 2002, 2004, 2006 Dmitry V. Levin <ldv@altlinux.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 static unsigned char lines, columns;
33 static void *screen_buf = 0;
40 const char clear_str[] = "\33[3J\33[H\33[J";
49 if (fstat(STDIN_FILENO, &st) == -1)
52 if (!S_ISCHR(st.st_mode))
55 if ((st.st_rdev >> 8) != 4)
58 i = st.st_rdev & 0xff;
59 sprintf(path, "/dev/vcsa%u", i);
60 vcs = open(path, O_RDWR);
64 if (read(vcs, &columns, 1) != 1)
67 if (read(vcs, &lines, 1) != 1)
70 size = 2 * lines * columns + 2;
71 screen_buf = malloc(size);
75 if (read(vcs, screen_buf, size) != (int) size)
85 if (failed && vcs >= 0)
91 /* There's no need to use ncurses */
92 if (write(STDOUT_FILENO, clear_str, sizeof(clear_str) - 1) !=
93 sizeof(clear_str) - 1)
104 if (lseek(vcs, 0, SEEK_SET))
106 if (write(vcs, &columns, 1) != 1)
108 if (write(vcs, &lines, 1) != 1)
110 if (write(vcs, screen_buf, 2 * lines * columns + 2) !=
111 2 * lines * columns + 2)