一,tcgetattr和tcsetattr的使用方法
#include <termios.h>
#include <unistd.h>
int tcgetattr(int fd, struct termios *termios_p);
int tcsetattr(int fd, int optional_actions,
const struct termios *termios_p);
int tcsendbreak(int fd, int duration);
int tcdrain(int fd);
int tcflush(int fd, int queue_selector);
int tcflow(int fd, int action);
void cfmakeraw(struct termios *termios_p);
speed_t cfgetispeed(const struct termios *termios_p);
代码
#include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <termios.h>
6 #include <errno.h>
7
8
9 int main(void)
10 {
11
12
13 struct termios term;
14
15 if ( tcgetattr(STDIN_FILENO, &term) == -1 ) //通过
16 {
17 printf("tcgetattr error is \n"/*, strerror(errno)*/);
18 return -1;
19 }
20
21 term.c_cc[VERASE] = '\b'; //这个代表前面字符的功能
22 //term.c_cc[VINTR]; //这个代表进程送一个SIGINT信号键
23
24 if ( tcsetattr(STDIN_FILENO, TCSANOW, &term) == -1)
{
26 printf("tcsetattr error is %s\r\n", strerror(errno));
27 return -1;
28 }
29
30
31 char buf[1024];
32 memset(buf, 0, sizeof(buf));
33
34 read(STDIN_FILENO, buf, sizeof(buf));
35
36 return 0;
37 }