/* Returns 0 if no waiting is needed or when no waiting is needed but the starting point should be reset (to current); or the number of milliseconds to wait to get back under the speed limit.  */
timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize, curl_off_t startsize, curl_off_t limit, struct curltime start, struct curltime now)
/* Returns 0 if no waiting is needed or when no waiting is needed but the starting point should be reset (to current); or the number of milliseconds to wait to get back under the speed limit.  */
timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize, curl_off_t startsize, curl_off_t limit, struct curltime start, struct curltime now)
{
  curl_off_t size = cursize - startsize;
  time_t minimum;
  time_t actual;
  if(!limit || !size)
    return 0;
  if(size < CURL_OFF_T_MAX/1000)
    minimum = (time_t) (CURL_OFF_T_C(1000) * size / limit);
  else {
    minimum = (time_t) (size / limit);
    if(minimum < TIME_T_MAX/1000)
      minimum *= 1000;
    else
      minimum = TIME_T_MAX;
  }
  actual = Curl_timediff(now, start);
  if(actual < minimum) {
    return (minimum - actual);
  }
  return 0;
}