Terminals 1301
Listing 62-1: Changing the terminal interrupt character
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––tty/new_intr.c
#include <termios.h>
#include <ctype.h>
#include "tlpi_hdr.h"
int
main(int argc, char *argv[])
{
struct termios tp;
int intrChar;
if (argc > 1 && strcmp(argv[1], "--help") == 0)
usageErr("%s [intr-char]\n", argv[0]);
/* Determine new INTR setting from command line */
if (argc == 1) { /* Disable */
intrChar = fpathconf(STDIN_FILENO, _PC_VDISABLE);
if (intrChar == -1)
errExit("Couldn't determine VDISABLE");
} else if (isdigit((unsigned char) argv[1][0])) {
intrChar = strtoul(argv[1], NULL, 0); /* Allows hex, octal */
} else { /* Literal character */
intrChar = argv[1][0];
}
/* Fetch current terminal settings, modify INTR character, and
push changes back to the terminal driver */
if (tcgetattr(STDIN_FILENO, &tp) == -1)
errExit("tcgetattr");
tp.c_cc[VINTR] = intrChar;
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tp) == -1)
errExit("tcsetattr");
exit(EXIT_SUCCESS);
}
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––tty/new_intr.c
62.5 Terminal Flags
Table 62-2 lists the settings controlled by each of the four flag fields of the termios
structure. The constants listed in this table correspond to single bits, except those
specifying the term mask, which are values spanning several bits; these may contain
one of a range of values, shown in parentheses. The column labeled SUSv3 indi-
cates whether the flag is specified in SUSv3. The Default column shows the default
settings for a virtual console login.