mirror of
https://frontier.innolan.net/rainlance/amiga-tz.git
synced 2026-05-03 06:46:08 +00:00
44 lines
1.4 KiB
C
44 lines
1.4 KiB
C
//--------------------------------------------------------------------------//
|
|
// This file is in the public domain, so clarified as of //
|
|
// 2009-05-17 by Arthur David Olson. //
|
|
//--------------------------------------------------------------------------//
|
|
#include "compiler.h"
|
|
#include "time_types.h"
|
|
//--------------------------------------------------------------------------//
|
|
|
|
bool increment_overflow(int *const ip, int j)
|
|
{
|
|
int const i = *ip;
|
|
|
|
/*
|
|
** If i >= 0 there can only be overflow if i + j > INT_MAX
|
|
** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow.
|
|
** If i < 0 there can only be overflow if i + j < INT_MIN
|
|
** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
|
|
*/
|
|
if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i)) {
|
|
return true;
|
|
}
|
|
|
|
*ip += j;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool increment_overflow_time(time_t *tp, int_fast32_t j)
|
|
{
|
|
/*
|
|
** This is like
|
|
** 'if (! (time_t_min <= *tp + j && *tp + j <= time_t_max)) ...',
|
|
** except that it does the right thing even if *tp + j would overflow.
|
|
*/
|
|
if (! (j < 0
|
|
? (TYPE_SIGNED(time_t) ? time_t_min - j <= *tp : -1 - j < *tp)
|
|
: *tp <= time_t_max - j))
|
|
return true;
|
|
*tp += j;
|
|
return false;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------//
|