version 1.1.1.2, 2003/04/13 18:21:21 |
version 1.1.1.3, 2011/09/16 17:47:07 |
|
|
/* |
/* |
* 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. |
|
|
{ |
{ |
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); |
|
|
#endif |
#endif |
reading = 0; |
reading = 0; |
if (n < 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 (-1); |
|
} |
return (n); |
return (n); |
} |
} |
|
|
|
|
{ |
{ |
register char *p; |
register char *p; |
register char *m; |
register char *m; |
|
int len; |
#if HAVE_ERRNO |
#if HAVE_ERRNO |
#if MUST_DEFINE_ERRNO |
#if MUST_DEFINE_ERRNO |
extern int errno; |
extern int errno; |
|
|
#else |
#else |
p = "cannot open"; |
p = "cannot open"; |
#endif |
#endif |
m = (char *) ecalloc(strlen(filename) + strlen(p) + 3, sizeof(char)); |
len = strlen(filename) + strlen(p) + 3; |
sprintf(m, "%s: %s", filename, p); |
m = (char *) ecalloc(len, sizeof(char)); |
|
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. }} |
|
|
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 |