APUE 笔记 Terminal I/O

18.2

1. Terminal I/O mode

canonical mode input processing :终端驱动(终端)每次处理一行(用户)输入,对应的实现模块是 terminal line discipline;

noncanonical mode input processing

2.

   struct termios {
     tcflag_t  c_iflag;    /* input flags */
     tcflag_t  c_oflag;    /* output flags */
     tcflag_t  c_cflag;    /* control flags */
     tcflag_t  c_lflag;    /* local flags */
     cc_t      c_cc[NCCS]; /* control characters */
   };


SUS 不在终端上使用ioctl,而是使用了针对终端的13个函数,这些函数一部分对termios结构进行操作,因外一些和terminal line discipline 模块和终端驱动交换,见下图:

Figure 18.8. Relationships among the terminal-related functions

(18.2)

18.3

1.Special Input Charaters

特殊字符有不同的用处,有一部分是和信号相关的:SIGINT、SIGQUIT、SIGTSTP、SIGQUIT,还有像EOF、CR、NL

Typical value 表示如何通过键盘操作打出这些输送字符。


Figure 18.10. Disable interrupt character and change end-of-file character

#include "apue.h"
#include <termios.h>
int
main(void)
{
    struct termios term;

    long           vdisable;


    if (isatty(STDIN_FILENO) == 0)//STDIN_FILENO和终端相关联,返回1,否则返回0
        err_quit("standard input is not a terminal device");
    if ((vdisable = fpathconf(STDIN_FILENO, _PC_VDISABLE)) < 0) //??
        err_quit("fpathconf error or _POSIX_VDISABLE not in effect");
    if (tcgetattr(STDIN_FILENO, &term) < 0) /* fetch tty state */
        err_sys("tcgetattr error");
    term.c_cc[VINTR] = vdisable;    /* disable INTR character */
    term.c_cc[VEOF]  = 2;           /* EOF is Control-B */
    if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) < 0) // 第二个参数控制设置何时起效,参考18.4
        err_sys("tcsetattr error");
    exit(0);
}



18.4

#include <termios.h>
int tcgetattr(int filedes, struct termios *termptr);
int tcsetattr(int filedes, int opt, const struct termios *termptr);

。。。下面的终端相关的,暂时不想看了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值