#ifndef VXWORKS_CFG 

#include <sgtty.h>
#include <sys/time.h>
#include <errno.h>

extern int errno;

int read_timeout(fd,buf,len,msec)
int fd;
char *buf;
int len;
int msec;
{
 int left;
 struct timeval tv;

 left = len;
 tv.tv_sec = msec / 1000;
 tv.tv_usec = (msec % 1000) * 1000;
 while (left > 0)
  { int fdmask = 1<<fd;
    int n;
    if ((n=select(32,&fdmask,0,0,&tv)) < 0)
     { return(-1);
     }
    if (n == 0)
     { return(len-left);
     }
    if ((n=read(fd,buf,left)) < 0)
     { return(-1);
     }
    if (n == 0)
     { return(len-left);
     }
    buf += n;
    left -= n;
  }
 return (len);
}

int read_restart(fd,buf,len)
int fd;
char *buf;
int len;
{
	/* a read that automatically restarts if a signal interrupts it */

	int n;

	do
	 { n = read(fd,buf,len);
	 }
	while (n < 0 && errno == EINTR);
	return (n);
}

#else

int read_restart(fd,buf,len)
int fd;
char *buf;
int len;
{
	/* do nothing for now because vXworks SIGNALS don't 
	   interrupt read (yet) */

	return (read(fd,buf,len));
}

#endif
