diff options
author | swhite <swhite@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2006-03-07 20:34:36 +0000 |
---|---|---|
committer | swhite <swhite@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2006-03-07 20:34:36 +0000 |
commit | 39eec0470c9c43316efac006749466976d9da1aa (patch) | |
tree | 0a33a8d1246f589a164c1331ac7942fe6f3caef7 /src/main/DefaultTimers.c | |
parent | 8546d803fcf8d8e323e2bffc9414b625ffe189c8 (diff) |
Fix for bug introduced by recent patch in systems with non-SYSV conformant
sys/time.h, such as Darwin 7.9.0.
The SYSV declaration is
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* and microsecond
};
I had used time_t and suseconds_t thinking they were the safe types to use,
but older BSD systems use longs for both. SYSV only specifies that they
be signed integral types, suseconds_t must hold 1,000,000 and -1, so long
should be enough for both.
See
http://www.opengroup.org/onlinepubs/007908799/xsh/systime.h.html
http://www.opengroup.org/onlinepubs/007908799/xsh/systypes.h.html
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4266 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/DefaultTimers.c')
-rw-r--r-- | src/main/DefaultTimers.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main/DefaultTimers.c b/src/main/DefaultTimers.c index 75537a26..954743a2 100644 --- a/src/main/DefaultTimers.c +++ b/src/main/DefaultTimers.c @@ -369,9 +369,12 @@ static void CCTKi_TimerGetTimeOfDaySet(int timernum, void *idata, cTimerVal *val (void) (timernum + 0); data = (t_GetTimeOfDayTimer *) idata; - data->total.tv_sec = (time_t)vals[0].val.d; - data->total.tv_usec = (suseconds_t)(1000000*vals[0].val.d) - - (suseconds_t)data->total.tv_sec; + /* Note: the struct timeval fields tv_sec and tv_usec are defined in SYSV + * as time_t and suseconds_t. But these types don't exist on all systems. + * They are signed integral types for which long should be enough. */ + data->total.tv_sec = (long)vals[0].val.d; + data->total.tv_usec = (long)(1000000*vals[0].val.d) + - (long)data->total.tv_sec; } |