elapsed time handling

The code has been assuming that time_t is some number of seconds.
That's valid for traditional Unix systems and for Posix compliant
systems but is not something guaranteed by the C standard.  (We ran
into a long time ago when trying out an alternate way to calculate
phase of moon.  That code made a similar assumption and broke one
of the ports.)

'ubirthday' also warrants being re-done but I've run out of energy.
This commit is contained in:
PatR
2021-08-25 14:14:23 -07:00
parent 52f5e79790
commit b1f3d1f864
5 changed files with 28 additions and 7 deletions

View File

@@ -964,6 +964,24 @@ debug_fields(const char *opts)
return;
}
/* convert from time_t to number of seconds */
long
timet_to_seconds(time_t ttim)
{
/* for Unix-based and Posix-compliant systems, a cast to 'long' would
suffice but the C Standard doesn't require time_t to be that simple */
return timet_delta(ttim, (time_t) 0);
}
/* calculate the difference in seconds between two time_t values */
long
timet_delta(time_t etim, time_t stim) /* end and start times */
{
/* difftime() is a STDC routine which returns the number of seconds
between two time_t values as a 'double' */
return (long) difftime(etim, stim);
}
#ifndef NODUMPENUMS
void
dump_enums(void)
@@ -1018,4 +1036,5 @@ dump_enums(void)
raw_print("");
}
#endif /* NODUMPENUMS */
/*allmain.c*/