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

Diff for /src/usr.bin/less/os.c between version 1.7 and 1.8

version 1.7, 2003/06/07 03:35:19 version 1.8, 2011/09/16 18:12:09
Line 1 
Line 1 
 /*  /*
  * Copyright (C) 1984-2002  Mark Nudelman   * Copyright (C) 1984-2011  Mark Nudelman
  *   *
  * You may distribute under the terms of either the GNU General Public   * You may distribute under the terms of either the GNU General Public
  * License or the Less License, as specified in the README file.   * License or the Less License, as specified in the README file.
Line 52 
Line 52 
 {  {
         register int n;          register int n;
   
   start:
 #if MSDOS_COMPILER==WIN32C  #if MSDOS_COMPILER==WIN32C
         if (ABORT_SIGS())          if (ABORT_SIGS())
                 return (READ_INTR);                  return (READ_INTR);
Line 109 
Line 110 
         }          }
 #endif  #endif
         if (n < 0)          if (n < 0)
                 return (errno == EINTR ? READ_INTR : -1);          {
   #if HAVE_ERRNO
                   /*
                    * Certain values of errno indicate we should just retry the read.
                    */
   #if MUST_DEFINE_ERRNO
                   extern int errno;
   #endif
   #ifdef EINTR
                   if (errno == EINTR)
                           goto start;
   #endif
   #ifdef EAGAIN
                   if (errno == EAGAIN)
                           goto start;
   #endif
   #endif
                   return (-1);
           }
         return (n);          return (n);
 }  }
   
Line 171 
Line 190 
 #endif  #endif
         len = strlen(filename) + strlen(p) + 3;          len = strlen(filename) + strlen(p) + 3;
         m = (char *) ecalloc(len, sizeof(char));          m = (char *) ecalloc(len, sizeof(char));
         snprintf(m, len, "%s: %s", filename, p);          SNPRINTF2(m, len, "%s: %s", filename, p);
         return (m);          return (m);
 }  }
   
   /* #define HAVE_FLOAT 0 */
   
           static POSITION
   muldiv(val, num, den)
           POSITION val, num, den;
   {
   #if HAVE_FLOAT
           double v = (((double) val) * num) / den;
           return ((POSITION) (v + 0.5));
   #else
           POSITION v = ((POSITION) val) * num;
   
           if (v / num == val)
                   /* No overflow */
                   return (POSITION) (v / den);
           else
                   /* Above calculation overflows;
                    * use a method that is less precise but won't overflow. */
                   return (POSITION) (val / (den / num));
   #endif
   }
   
 /*  /*
  * Return the ratio of two POSITIONS, as a percentage.   * Return the ratio of two POSITIONS, as a percentage.
  * {{ Assumes a POSITION is a long int. }}   * {{ Assumes a POSITION is a long int. }}
Line 183 
Line 224 
 percentage(num, den)  percentage(num, den)
         POSITION num, den;          POSITION num, den;
 {  {
         POSITION num100 = num * 100;          return (int) muldiv(num,  (POSITION) 100, den);
   
         if (num100 / 100 == num)  
                 return (num100 / den);  
         else  
                 return (num / (den / 100));  
 }  }
   
 /*  /*
  * Return the specified percentage of a POSITION.   * Return the specified percentage of a POSITION.
  */   */
         public POSITION          public POSITION
 percent_pos(pos, percent)  percent_pos(pos, percent, fraction)
         POSITION pos;          POSITION pos;
         int percent;          int percent;
           long fraction;
 {  {
         POSITION result100;          /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */
           POSITION perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100);
   
         if (percent == 0)          if (perden == 0)
                 return (0);                  return (0);
         else if ((result100 = pos * percent) / percent == pos)          return (POSITION) muldiv(pos, perden, (POSITION) NUM_FRAC_DENOM);
                 return (result100 / 100);  
         else  
                 return (percent * (pos / 100));  
 }  }
   
 #if !HAVE_STRCHR  #if !HAVE_STRCHR

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8