00001 #include <termios.h> 00002 #include <stdio.h> 00003 #include <string.h> 00004 #include <errno.h> 00005 00006 #include <unistd.h> 00007 #include <stdlib.h> 00008 #include <fcntl.h> 00009 #include <sys/time.h> 00010 00011 #include <sys/types.h> 00012 #include <sys/uio.h> 00013 00014 int dev_raw (int fd) 00015 { 00016 struct termios termios_p; 00017 00018 if (tcgetattr (fd, &termios_p)) 00019 return (-1); 00020 00021 termios_p.c_cc[VMIN] = 1; 00022 termios_p.c_cc[VTIME] = 0; 00023 termios_p.c_lflag &= ~(ECHO | ICANON | ISIG | 00024 ECHOE | ECHOK | ECHONL); 00025 termios_p.c_oflag &= ~(OPOST); 00026 return (tcsetattr (fd, TCSANOW, &termios_p)); 00027 } 00028 00029 int dev_unraw (int fd) 00030 { 00031 struct termios termios_p; 00032 00033 if (tcgetattr (fd, &termios_p)) 00034 return (-1); 00035 00036 termios_p.c_lflag |= (ECHO | ICANON | ISIG | 00037 ECHOE | ECHOK | ECHONL); 00038 termios_p.c_oflag |= (OPOST); 00039 return (tcsetattr (fd, TCSAFLUSH, &termios_p)); 00040 }