int saved_errno = errno;
PUBLIC int HTDoRead ARGS3(	int,		fildes,	void *, 	buf,	unsigned,	nbyte){    int ready, ret;    fd_set readfds;    struct timeval timeout;    int tries=0;#if defined(UNIX) || defined(UCX)    int nb;#endif /* UCX, BSN */#ifdef UNIX    if (fildes == 0) {	/*	 *  0 can be a valid socket fd, but if it's a tty something must	 *  have gone wrong. - kw	 */	if (isatty(fildes)) {	    CTRACE(tfp, "HTDoRead - refusing to read fd 0 which is a tty!\n");	    return -1;	}    } else#endif    if (fildes <= 0)	return -1;    if (HTCheckForInterrupt()) {	SOCKET_ERRNO = EINTR;	return (HT_INTERRUPTED);    }#if !defined(NO_IOCTL)    ready = 0;#else    ready = 1;#endif /* bypass for NO_IOCTL */    while (!ready) {	/*	**  Protect against an infinite loop.	*/	if (tries++ >= 180000) {	    HTAlert(gettext("Socket read failed for 180,000 tries."));	    SOCKET_ERRNO = EINTR;	    return HT_INTERRUPTED;	}	/*	**  If we suspend, then it is possible that select will be	**  interrupted.  Allow for this possibility. - JED	*/	do {	    timeout.tv_sec = 0;	    timeout.tv_usec = 100000;	    FD_ZERO(&readfds);	    FD_SET(fildes, &readfds);#ifdef SOCKS	    if (socks_flag)		ret = Rselect(FD_SETSIZE,			      (void *)&readfds, NULL, NULL, &timeout);	    else#endif /* SOCKS */		ret = select(FD_SETSIZE,			     (void *)&readfds, NULL, NULL, &timeout);	} while ((ret == -1) && (errno == EINTR));	if (ret < 0) {	    return -1;	} else if (ret > 0) {	    ready = 1;	} else if (HTCheckForInterrupt()) {	    SOCKET_ERRNO = EINTR;	    return HT_INTERRUPTED;	}    }#if !defined(UCX) || !defined(VAXC)#ifdef UNIX    while ((nb = SOCKET_READ (fildes, buf, nbyte)) == -1) {	int saved_errno = errno;	if (errno == EINTR)	    continue;#ifdef ERESTARTSYS	if (errno == ERESTARTSYS)	    continue;#endif /* ERESTARTSYS */	HTInetStatus("read");	errno = saved_errno;	/* our caller may check it */	break;    }    return nb;#else  /* UNIX */    return SOCKET_READ (fildes, buf, nbyte);#endif /* !UNIX */#else  /* UCX && VAXC */    /*    **	VAXC and UCX problem only.    */    errno = vaxc$errno = 0;    nb = SOCKET_READ (fildes, buf, nbyte);    CTRACE(tfp,	   "Read - nb,errno,vaxc$errno: %d %d %d\n", nb,errno,vaxc$errno);    if ((nb <= 0) && TRACE)	perror ("HTTCP.C:HTDoRead:read");	   /* RJF */    /*    **	An errno value of EPIPE and nb < 0 indicates end-of-file on VAXC.    */    if ((nb <= 0) && (errno == EPIPE)) {	nb = 0;	errno = 0;    }    return nb;#endif /* UCX, BSN */}