next up previous contents
Next: 10.4 Process information and Up: 10 Porting Applications to Previous: 10.2.4 Signals supported by

10.3 Terminal I/O

As with signals, terminal I/O control has three different implementations under SVR4, BSD, and POSIX.1.

SVR4 uses the termio structure, and various ioctl calls (such as TCSETA, TCGETA, and so forth) on a terminal device to obtain and set parameters with the termio structure. This structure looks like:

  struct termio {
    unsigned short c_iflag;  /* Input modes */
    unsigned short c_oflag;  /* Output modes */
    unsigned short c_cflag;  /* Control modes */
    unsigned short c_lflag;  /* Line discipline modes */
    char c_line;             /* Line discipline */
    unsigned char c_cc[NCC]; /* Control characters */

Under BSD, the sgtty structure is used with various ioctl calls, such as TIOCGETP, TIOCSETP, and so forth.

Under POSIX, the termios struct is used, along with various functions defined by POSIX.1, such as tcsetattr and tcgetattr. The termios structure is identical to struct termio used by SVR4, but the types are renamed (such as tcflag_t instead of unsigned short), and NCCS is used for the size of the c_cc array.

Under Linux, both POSIX.1 termios and SVR4 termio are supported directly by the kernel. This means that if your program uses either of these methods for accessing terminal I/O, it should compile directly under Linux. If you're ever in doubt, it's easy to modify code using termio to use termios, using a bit of knowledge of both methods. Hopefully, this shouldn't ever be necessary. But, do pay attention if a program attempts to use the c_line field in the termio structure. For nearly all applications, this should be N_TTY, and if the program assumes that some other line discipline is available you might have trouble.

If your program uses the BSD sgtty implementation, you can link against libbsd.a as described above. This will provide a replacement for ioctl which will resubmit the terminal I/O requests in terms of the POSIX termios calls used by the kernel. When compiling such a program, if symbols such as TIOCGETP are undefined, you will need to link against libbsd.

Converted on:
Fri Mar 29 14:43:04 EST 1996