#include #include #include #include #include // // // using namespace std; int main(int argc, char** argv) { int master, slave; char *name; char *buf = (char*)malloc(4096); master = open("/dev/ptmx",O_RDWR|O_NOCTTY|O_NONBLOCK); if (master < 0) return 0; if (grantpt (master) < 0 || unlockpt (master) < 0) throw 1; name = ptsname (master); if (name == NULL) throw 1; fd_set readset; timeval tv; tv.tv_sec = 30; tv.tv_usec = 0; while (true){ FD_ZERO(&readset); FD_SET(0, &readset); FD_SET(master, &readset); if(select(master+1, &readset, NULL, NULL, &tv) <= 0) { continue; } //stdin if(FD_ISSET(0, &readset)) { int bytesRead = read(0,buf,4096); write(master,buf,bytesRead); } //pty if(FD_ISSET(master, &readset)) { int bytesRead; while (bytesRead = read(master,buf,4096) > 0){ write(1,buf,bytesRead); } } } return (EXIT_SUCCESS); }