change a console's protocol emulation
#include <sys/console.h> int console_protocol( struct _console_ctrl *cc, int console, int protocol );
The console_protocol() function is used to change a console's protocol emulation.
The console argument has a value of 1 to represent the device named /dev/con1, a value of 2 for /dev/con2, and so on. A value of 0 for console indicates the default console (that is, the one used by console_open()). A value of -1 for console indicates the currently visible console.
The currently available protocols are:
If protocol is -1, the protocol for the specified console is unchanged. (This allows you to query a console protocol without changing it, since the previous protocol value is returned.)
Upon successful completion, the console_protocol() function returns the previous protocol value; otherwise -1 is returned and errno is set.
#include <stdio.h> #include <fcntl.h> #include <sys/console.h> #include <errno.h> #include <stdlib.h> main() { struct _console_ctrl *cc; int protocol; /* * Open up a channel to the console driver * associated with standard input */ cc = console_open(fileno(stdin), O_RDWR); if( cc ) { /* * Query the current protocol of stdin's console */ protocol = console_protocol(cc, 0, -1); if( protocol == -1 ) { if( errno == ENOSYS ) { protocol = _CON_PROT_QNX4; } else { perror("console_protocol"); exit(EXIT_FAILURE); } } printf("Current protocol is %d\n", protocol); /* * Change to ANSI protocol */ protocol = console_protocol(cc, 0, _CON_PROT_ANSI); if( protocol == -1 ) { perror("console_protocol"); exit(EXIT_FAILURE); } printf("This is now in ANSI mode\n"); /* * Restore protocol */ console_protocol(cc, 0, protocol); printf( "This is now returned to previous mode\n" ); console_close(cc); } }
QNX
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
console_active(), console_arm(), console_close(), console_ctrl(), console_font(), console_info(), console_open(), console_read(), console_size(), console_state(), console_write(), errno