=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/os.c,v retrieving revision 1.7 retrieving revision 1.8 diff -c -r1.7 -r1.8 *** src/usr.bin/less/os.c 2003/06/07 03:35:19 1.7 --- src/usr.bin/less/os.c 2011/09/16 18:12:09 1.8 *************** *** 1,5 **** /* ! * Copyright (C) 1984-2002 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. --- 1,5 ---- /* ! * Copyright (C) 1984-2011 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. *************** *** 52,57 **** --- 52,58 ---- { register int n; + start: #if MSDOS_COMPILER==WIN32C if (ABORT_SIGS()) return (READ_INTR); *************** *** 109,115 **** } #endif if (n < 0) ! return (errno == EINTR ? READ_INTR : -1); return (n); } --- 110,134 ---- } #endif if (n < 0) ! { ! #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); } *************** *** 171,180 **** #endif len = strlen(filename) + strlen(p) + 3; m = (char *) ecalloc(len, sizeof(char)); ! snprintf(m, len, "%s: %s", filename, p); return (m); } /* * Return the ratio of two POSITIONS, as a percentage. * {{ Assumes a POSITION is a long int. }} --- 190,221 ---- #endif len = strlen(filename) + strlen(p) + 3; m = (char *) ecalloc(len, sizeof(char)); ! SNPRINTF2(m, len, "%s: %s", filename, p); 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. * {{ Assumes a POSITION is a long int. }} *************** *** 183,212 **** percentage(num, den) POSITION num, den; { ! POSITION num100 = num * 100; ! ! if (num100 / 100 == num) ! return (num100 / den); ! else ! return (num / (den / 100)); } /* * Return the specified percentage of a POSITION. */ public POSITION ! percent_pos(pos, percent) POSITION pos; int percent; { ! POSITION result100; ! if (percent == 0) return (0); ! else if ((result100 = pos * percent) / percent == pos) ! return (result100 / 100); ! else ! return (percent * (pos / 100)); } #if !HAVE_STRCHR --- 224,247 ---- percentage(num, den) POSITION num, den; { ! return (int) muldiv(num, (POSITION) 100, den); } /* * Return the specified percentage of a POSITION. */ public POSITION ! percent_pos(pos, percent, fraction) POSITION pos; int percent; + long fraction; { ! /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */ ! POSITION perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100); ! if (perden == 0) return (0); ! return (POSITION) muldiv(pos, perden, (POSITION) NUM_FRAC_DENOM); } #if !HAVE_STRCHR