rem: timeout.tv_sec  = 5; timeout.tv_usec = 0;
add: timeout.tv_sec  = serial_recv_timeout / 1000L; timeout.tv_usec = (serial_recv_timeout % 1000L) * 1000;
context: int serial_recv(int fd, char * buf, size_t buflen){  struct timeval timeout;  fd_set rfds;  int nfds;  int rc;  char * p = buf;  size_t len = 0;  timeout.tv_sec  = 5;  timeout.tv_usec = 0;  while (len < buflen) {    FD_ZERO(&rfds);    FD_SET(fd, &rfds);  reselect:    nfds = select(fd+1, &rfds, NULL, NULL, &timeout);    if (nfds == 0) {      fprintf(stderr,               "%s: serial_recv(): programmer is not responding\n",              progname);      exit(1);    }    else if (nfds == -1) {      if (errno == EINTR) {        goto reselect;      }      else {        fprintf(stderr, "%s: serial_recv(): select(): %s\n",                progname, strerror(errno));        exit(1);      }    }    rc = read(fd, p, 1);    if (rc < 0) {      fprintf(stderr, "%s: serial_recv(): read error: %s\n",              progname, strerror(errno));      exit(1);    }    p++;    len++;  }  p = buf;  if (verbose > 3)  {      fprintf(stderr, "%s: Recv: ", progname);      while (len) {        unsigned char c = *p;        if (isprint(c)) {          fprintf(stderr, "%c ", c);        }        else {          fprintf(stderr, ". ");        }        fprintf(stderr, "[%02x] ", c);        p++;        len--;      }      fprintf(stderr, "\n");  }  return 0;}