/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" #include "ptydrv.h" #include #include #include #include result duplex(int fd1, int fd2) { fd_set rfds; int nfd, rcnt; char buf[BUF_SIZE]; FD_ZERO(&rfds); FD_SET(fd1, &rfds); FD_SET(fd2, &rfds); timeout: restart: switch(select(2, &rfds, NULL, NULL, NULL)) { case 0: goto timeout; case FAIL: if(errno == EINTR) goto restart; else return FAIL; default: if(FD_ISSET(fd1, &rfds)) { rcnt = read(fd1, buf, BUF_SIZE); if(cnt == FAIL) got FAIL; wcnt = write(fd1, buf, BUF_SIZE); } if(FD_ISSET(fd2, &rfds)) { buf[BUF_SIZE]; } goto restart; } }