diff options
author | delphij <delphij@FreeBSD.org> | 2007-06-04 01:42:54 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2007-06-04 01:42:54 +0000 |
commit | 9b5d103b5b51a6fea5caf2c8b1fc678d65a357c9 (patch) | |
tree | f7d1bd15b558b3590d7bb4d4e31ef8833e0a1171 /contrib/less/os.c | |
parent | 05dd7cf6267b7b4d66cfc8e51b6d7e47d0eba220 (diff) | |
parent | 7672cb6e48e2ed472cbd72caaa0eb155608a644d (diff) | |
download | FreeBSD-src-9b5d103b5b51a6fea5caf2c8b1fc678d65a357c9.zip FreeBSD-src-9b5d103b5b51a6fea5caf2c8b1fc678d65a357c9.tar.gz |
This commit was generated by cvs2svn to compensate for changes in r170256,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'contrib/less/os.c')
-rw-r--r-- | contrib/less/os.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/contrib/less/os.c b/contrib/less/os.c index 01acd6c..fef5f94 100644 --- a/contrib/less/os.c +++ b/contrib/less/os.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2005 Mark Nudelman + * Copyright (C) 1984-2007 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. @@ -74,6 +74,7 @@ iread(fd, buf, len) { register int n; +start: #if MSDOS_COMPILER==WIN32C if (ABORT_SIGS()) return (READ_INTR); @@ -156,7 +157,25 @@ iread(fd, buf, len) #endif reading = 0; 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); } @@ -251,18 +270,25 @@ percentage(num, den) * Return the specified percentage of a POSITION. */ public POSITION -percent_pos(pos, percent) +percent_pos(pos, percent, fraction) POSITION pos; int percent; + long fraction; { - POSITION result100; + /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */ + long perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100); + POSITION temp; - if (percent == 0) + if (perden == 0) return (0); - else if ((result100 = pos * percent) / percent == pos) - return (result100 / 100); + temp = pos * perden; /* This might overflow. */ + if (temp / perden == pos) + /* No overflow */ + return (temp / NUM_FRAC_DENOM); else - return (percent * (pos / 100)); + /* Above calculation overflows; + * use a method that is less precise but won't overflow. */ + return (perden * (pos / NUM_FRAC_DENOM)); } #if !HAVE_STRCHR |