Deleted Added
full compact
os.c (63128) os.c (89019)
1/*
2 * Copyright (C) 1984-2000 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.

--- 19 unchanged lines hidden (view full) ---

28#include <time.h>
29#endif
30#if HAVE_ERRNO_H
31#include <errno.h>
32#endif
33#if HAVE_VALUES_H
34#include <values.h>
35#endif
1/*
2 * Copyright (C) 1984-2000 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.

--- 19 unchanged lines hidden (view full) ---

28#include <time.h>
29#endif
30#if HAVE_ERRNO_H
31#include <errno.h>
32#endif
33#if HAVE_VALUES_H
34#include <values.h>
35#endif
36#if HAVE_LIMITS_H
37#include <limits.h>
38#endif
39
40#if HAVE_TIME_T
41#define time_type time_t
42#else
43#define time_type long
44#endif
45
46/*

--- 181 unchanged lines hidden (view full) ---

228 p = "cannot open";
229#endif
230 m = (char *) ecalloc(strlen(filename) + strlen(p) + 3, sizeof(char));
231 sprintf(m, "%s: %s", filename, p);
232 return (m);
233}
234
235/*
36
37#if HAVE_TIME_T
38#define time_type time_t
39#else
40#define time_type long
41#endif
42
43/*

--- 181 unchanged lines hidden (view full) ---

225 p = "cannot open";
226#endif
227 m = (char *) ecalloc(strlen(filename) + strlen(p) + 3, sizeof(char));
228 sprintf(m, "%s: %s", filename, p);
229 return (m);
230}
231
232/*
236 * Return the largest possible number that can fit in a long.
237 */
238 static long
239get_maxlong()
240{
241#ifdef LONG_MAX
242 return (LONG_MAX);
243#else
244#ifdef MAXLONG
245 return (MAXLONG);
246#else
247 long n, n2;
248
249 /*
250 * Keep doubling n until we overflow.
251 * {{ This actually only returns the largest power of two that
252 * can fit in a long, but percentage() doesn't really need
253 * it any more accurate than that. }}
254 */
255 n2 = 128; /* Hopefully no maxlong is less than 128! */
256 do {
257 n = n2;
258 n2 *= 2;
259 } while (n2 / 2 == n);
260 return (n);
261#endif
262#endif
263}
264
265/*
266 * Return the ratio of two POSITIONS, as a percentage.
267 * {{ Assumes a POSITION is a long int. }}
268 */
269 public int
270percentage(num, den)
271 POSITION num, den;
272{
233 * Return the ratio of two POSITIONS, as a percentage.
234 * {{ Assumes a POSITION is a long int. }}
235 */
236 public int
237percentage(num, den)
238 POSITION num, den;
239{
273 if (num <= get_maxlong() / 100)
274 return ((100 * num) / den);
240 POSITION num100 = num * 100;
241
242 if (num100 / 100 == num)
243 return (num100 / den);
275 else
276 return (num / (den / 100));
277}
278
279/*
280 * Return the specified percentage of a POSITION.
244 else
245 return (num / (den / 100));
246}
247
248/*
249 * Return the specified percentage of a POSITION.
281 * {{ Assumes a POSITION is a long int. }}
282 */
283 public POSITION
284percent_pos(pos, percent)
285 POSITION pos;
286 int percent;
287{
250 */
251 public POSITION
252percent_pos(pos, percent)
253 POSITION pos;
254 int percent;
255{
288 if (pos <= get_maxlong() / 100)
289 return ((percent * pos) / 100);
256 POSITION result100;
257
258 if (percent == 0)
259 return (0);
260 else if ((result100 = pos * percent) / percent == pos)
261 return (result100 / 100);
290 else
291 return (percent * (pos / 100));
292}
293
262 else
263 return (percent * (pos / 100));
264}
265
266#if !HAVE_STRCHR
267/*
268 * strchr is used by regexp.c.
269 */
270 char *
271strchr(s, c)
272 char *s;
273 int c;
274{
275 for ( ; *s != '\0'; s++)
276 if (*s == c)
277 return (s);
278 if (c == '\0')
279 return (s);
280 return (NULL);
281}
282#endif
283
284#if !HAVE_MEMCPY
285 VOID_POINTER
286memcpy(dst, src, len)
287 VOID_POINTER dst;
288 VOID_POINTER src;
289 int len;
290{
291 char *dstp = (char *) dst;
292 char *srcp = (char *) src;
293 int i;
294
295 for (i = 0; i < len; i++)
296 dstp[i] = srcp[i];
297 return (dst);
298}
299#endif
300
294#ifdef _OSK_MWC32
295
296/*
297 * This implements an ANSI-style intercept setup for Microware C 3.2
298 */
299 public int
300os9_signal(type, handler)
301 int type;
302 RETSIGTYPE (*handler)();
303{
304 intercept(handler);
305}
306
307#include <sgstat.h>
308
301#ifdef _OSK_MWC32
302
303/*
304 * This implements an ANSI-style intercept setup for Microware C 3.2
305 */
306 public int
307os9_signal(type, handler)
308 int type;
309 RETSIGTYPE (*handler)();
310{
311 intercept(handler);
312}
313
314#include <sgstat.h>
315
309 public int
316 int
310isatty(f)
311 int f;
312{
313 struct sgbuf sgbuf;
314
315 if (_gs_opt(f, &sgbuf) < 0)
316 return -1;
317 return (sgbuf.sg_class == 0);
318}
319
320#endif
317isatty(f)
318 int f;
319{
320 struct sgbuf sgbuf;
321
322 if (_gs_opt(f, &sgbuf) < 0)
323 return -1;
324 return (sgbuf.sg_class == 0);
325}
326
327#endif