Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS® UNIX | both |
#define _OPEN_SYS_PTY_EXTENSIONS
#include <termios.h>
int __tcsettables(int fildes, size_t termcplen,
const struct __termcp *termcpptr,
const char atoe[256],
const char etoa[256]);
The __tcsettables() function changes the data conversion environment for terminal sessions that support the “forward code page names and tables” Code Page Change Notification (CPCN) capability. The OCS remote-tty (rty) device driver supports this capability.
This value is not used by the OCS rty device driver and thus has no effect.
__tccp_fromname is case-sensitive.
__tccp_toname is case-sensitive.
For terminal sessions that use the OCS rty device driver, the ASCII/EBCDIC data conversion is performed outboard by OCS on the AIX server system. Use the __tcsettables() function to specify new code pages and conversion tables to be used in the data conversion.
During its processing of the __tcsettables() function, the OCS rty device driver applies the new code page names once the outbound data queue is drained. When this occurs, the rty input data queue is also flushed and the new conversion environment takes effect.
When __tcsettables() is issued from a process in a background process group, SIGTTOU is processing in this way:
Processing for SIGTTOU | Expected Behavior |
---|---|
Default or signal handler | The SIGTTOU signal is generated. The function is not performed. __tcsettables() returns -1 and sets errno to EINTR. |
Ignored or blocked | The SIGTTOU signal is not sent. The function continues normally. |
If successful, __tcsettables() returns 0.
#define _OPEN_SYS_PTY_EXTENSIONS
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <termios.h>
#include <iconv.h>
main()
{
struct __termcp mytermcp; /* local __termcp */
unsigned char *intabptr; /* pointer to input table */
unsigned char *outtabptr; /* pointer to output table */
unsigned char intab[256],
atoe[256],
etoa[256]; /* conversion tables */
iconv_t cd; /* conversion descriptor */
size_t inleft; /* number of bytes left in input */
size_t outleft; /* number of bytes left in output */
int i; /* loop variable */
int rv; /* return value */
int cterm_fd; /* file descriptor for controlling
terminal */
if ((cterm_fd = open("/dev/tty",O_RDWR)) == -1)
{
printf("No controlling terminal established. ");
printf("Code pages were not changed.\n");
exit(0);
}
if ((rv = __tcgetcp(cterm_fd,sizeof(mytermcp),&mytermcp))== -1)
{
perror("__tcgetcp() error");
exit(1);
}
if (_TCCP_BINARY == (mytermcp.__tccp_flags & _TCCP_BINARY))
{
printf("Binary mode is in effect. No change made.\n");
exit(0);
}
if (rv == _CPCN_TABLES) {
/* build ASCII -> EBCDIC conversion table */
strcpy(mytermcp.__tccp_fromname,"IBM-850");
if ((cd = iconv_open(mytermcp.__tccp_toname,
mytermcp.__tccp_fromname)) ==
(iconv_t) (-1)) {
fprintf(stderr,"Cannot open converter from %s to %s\n",
mytermcp.__tccp_fromname,mytermcp.__tccp_toname);
exit(1);
}
/* build input table with character values of 00 - FF */
for (i=0; i<256; i++ ) {
intab[i] = (unsigned char) i;
} /* endfor */
inleft = 256;
outleft = 256;
intabptr = intab;
outtabptr = atoe;
/* build ASCII -> EBCDIC conversion table. */
rv = iconv(cd,&intabptr, &inleft, &outtabptr, &outleft);
if (rv == -1) {
fprintf(stderr,"Error in building ASCII to EBCDIC table\n");
exit(1);
}
iconv_close(cd);
/* build EBCDIC -> ASCII conversion table */
if ((cd = iconv_open(mytermcp.__tccp_fromname,
mytermcp.__tccp_toname)) ==
(iconv_t) (-1)) {
fprintf(stderr,"Cannot open converter from %s to %s\n",
mytermcp.__tccp_toname,mytermcp.__tccp_fromname);
exit(1);
}
inleft = 256;
outleft = 256;
intabptr = intab;
outtabptr = etoa;
rv = iconv(cd,&intabptr, &inleft, &outtabptr, &outleft);
if (rv == -1) {
fprintf(stderr,"Error in building EBCDIC to ASCII table\n");
exit(1);
}
iconv_close(cd);
/*
* Change the data conversion to use IBM-850 as the ASCII source
*/
if (__tcsettables(cterm_fd, sizeof(mytermcp), &mytermcp,
atoe,etoa) == -1) {
perror("__tcsettables() error");
exit(1);
} else {
printf("Data conversion now using ASCII IBM-850\n");
} /* endif */
} /* endif */
close(cterm_fd);
} /* main */
Data conversion now using ASCII IBM-850.