if (res == -1 && errno != EAGAIN) { close(pd[1]);
if (res == -1 && errno != EAGAIN)
main(argc, argv)	int argc;	char *argv[];{	int pd[2], rfds;	int width = 1, off, n, res;	char buf[1024];	int pid, stat;	if (!(isatty(0) && isatty(1)))		execv("/usr/bin/gnubc", argv);	/* Ok, we need to go non-interactive */	if (pipe(pd) == -1) {		perror("pipe");		exit(1);	}	pid = fork();	switch(pid) {	case -1:		perror("vfork");		exit(1);	case 0:		dup2(pd[0], 0);		/* stdin = pipe */		close(pd[0]);		close(pd[1]);		execv("/usr/bin/gnubc", argv);		exit(1);	default:		close(pd[0]);		break;	}	width = pd[1];	rfds = (1 << 0) || (1 << pd[1]);	while (1) {		switch (select(width, (fd_set *)&rfds, NULL, NULL, NULL)) {		case -1:		case 0:			break;		default:			if (rfds & (1<<0) == 0)				break;			n = read(0, buf, sizeof buf);			if (n == 0) {				close(pd[1]);				goto done;			}			off = 0;			while (off < n) {				res = write(pd[1], buf + off, n - off);				if (res == -1 && errno != EAGAIN) {					close(pd[1]);					goto done;				}				off += res;			}		}	}done:	close(pd[1]);	waitpid(pid, &stat, 0);	exit(WEXITSTATUS(stat));}