1
0
mirror of https://frontier.innolan.net/rainlance/amiga-tz.git synced 2025-11-20 04:51:28 +00:00
Files
amiga-tz/difftime.c
Paul Eggert 400ecf36bb Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better.  Mostly this consists of using function
prototypes.  In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition.  But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00

58 lines
1.5 KiB
C

/*
** This file is in the public domain, so clarified as of
** 1996-06-05 by Arthur David Olson.
*/
/*LINTLIBRARY*/
#include "private.h" /* for time_t, TYPE_INTEGRAL, and TYPE_SIGNED */
double
difftime(const time_t time1, const time_t time0)
{
/*
** If (sizeof (double) > sizeof (time_t)) simply convert and subtract
** (assuming that the larger type has more precision).
** This is the common real-world case circa 2004.
*/
if (sizeof (double) > sizeof (time_t))
return (double) time1 - (double) time0;
if (!TYPE_INTEGRAL(time_t)) {
/*
** time_t is floating.
*/
return time1 - time0;
}
if (!TYPE_SIGNED(time_t)) {
/*
** time_t is integral and unsigned.
** The difference of two unsigned values can't overflow
** if the minuend is greater than or equal to the subtrahend.
*/
if (time1 >= time0)
return time1 - time0;
else return -((double) (time0 - time1));
}
/*
** time_t is integral and signed.
** Handle cases where both time1 and time0 have the same sign
** (meaning that their difference cannot overflow).
*/
if ((time1 < 0) == (time0 < 0))
return time1 - time0;
/*
** time1 and time0 have opposite signs.
** Punt if unsigned long is too narrow.
*/
if (sizeof (unsigned long) < sizeof (time_t))
return (double) time1 - (double) time0;
/*
** Stay calm...decent optimizers will eliminate the complexity below.
*/
if (time1 >= 0 /* && time0 < 0 */)
return (unsigned long) time1 +
(unsigned long) (-(time0 + 1)) + 1;
return -(double) ((unsigned long) time0 +
(unsigned long) (-(time1 + 1)) + 1);
}