2 * Copyright (C) 1984-2012 Mark Nudelman
3 * Modified for use with illumos by Garrett D'Amore.
4 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
13 * Operating system dependent routines.
15 * Most of the stuff in here is based on Unix, but an attempt
16 * has been made to make things work on other operating systems.
17 * This will sometimes result in a loss of functionality, unless
18 * someone rewrites code specifically for the new operating system.
20 * The makefile provides defines to decide whether various
21 * Unix features are present.
30 extern volatile sig_atomic_t sigs
;
33 * Like read() system call, but is deliberately interruptible.
36 iread(int fd
, unsigned char *buf
, unsigned int len
)
42 n
= read(fd
, buf
, len
);
45 * Certain values of errno indicate we should just retry the
58 * errno_message: Return an error message based on the value of "errno".
61 errno_message(char *filename
)
63 return (easprintf("%s: %s", filename
, strerror(errno
)));
67 muldiv(off_t val
, off_t num
, off_t den
)
69 double v
= (((double)val
) * num
) / den
;
70 return ((off_t
)(v
+ 0.5));
74 * Return the ratio of two off_t, as a percentage.
75 * {{ Assumes a off_t is a long int. }}
78 percentage(off_t num
, off_t den
)
80 return ((int)muldiv(num
, (off_t
)100, den
));
84 * Return the specified percentage of a off_t.
87 percent_pos(off_t pos
, int percent
, long fraction
)
90 * Change percent (parts per 100) to perden
91 * (parts per NUM_FRAC_DENOM).
93 off_t perden
= (percent
* (NUM_FRAC_DENOM
/ 100)) + (fraction
/ 100);
97 return (muldiv(pos
, perden
, (off_t
)NUM_FRAC_DENOM
));