[BACK]Return to linenum.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Diff for /src/usr.bin/less/linenum.c between version 1.16 and 1.17

version 1.16, 2016/12/30 19:52:43 version 1.17, 2017/11/27 23:39:03
Line 33 
Line 33 
  * called to make sure we cache line numbers often enough.   * called to make sure we cache line numbers often enough.
  */   */
   
   #include <sys/time.h>
   
   #include <time.h>
   
 #include "less.h"  #include "less.h"
   
 /*  /*
Line 197 
Line 201 
 }  }
   
 static int loopcount;  static int loopcount;
 static time_t startime;  static struct timespec timeout;
   
 static void  static void
   timeout_set(int seconds)
   {
           clock_gettime(CLOCK_MONOTONIC, &timeout);
           timeout.tv_sec += seconds;
   }
   
   static int
   timeout_elapsed(void)
   {
           struct timespec now;
   
           clock_gettime(CLOCK_MONOTONIC, &now);
           return timespeccmp(&now, &timeout, >=);
   }
   
   static void
 longish(void)  longish(void)
 {  {
         if (loopcount >= 0 && ++loopcount > 100) {          if (loopcount >= 0 && ++loopcount > 100) {
                 loopcount = 0;                  loopcount = 0;
                 if (time(NULL) >= startime + LONGTIME) {                  if (timeout_elapsed()) {
                         ierror("Calculating line numbers", NULL);                          ierror("Calculating line numbers", NULL);
                         loopcount = -1;                          loopcount = -1;
                 }                  }
Line 274 
Line 294 
          * The decision is based on which way involves           * The decision is based on which way involves
          * traversing fewer bytes in the file.           * traversing fewer bytes in the file.
          */           */
         startime = time(NULL);          timeout_set(LONGTIME);
         if (p == &anchor || pos - p->prev->pos < p->pos - pos) {          if (p == &anchor || pos - p->prev->pos < p->pos - pos) {
                 /*                  /*
                  * Go forward.                   * Go forward.

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17