mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-27 13:34:00 +01:00
Add common code to support realtime clocks that store year without century.
Most realtime clocks store the year as 2 BCD digits. Some add a century bit to extend the range another hundred years. Every clock driver has its own code to determine the century and pass a full year value to clock_ct_to_ts(). Now clock drivers can just convert BCD to bin and store the result in the clocktime struct and let the common code figure out the century. Clocks with a century bit can just add 100 to year if the century bit is on.
This commit is contained in:
parent
e650280282
commit
f1b21e2c92
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=321400
@ -142,18 +142,27 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec *ts)
|
||||
{
|
||||
int i, year, days;
|
||||
|
||||
year = ct->year;
|
||||
|
||||
if (ct_debug) {
|
||||
printf("ct_to_ts(");
|
||||
print_ct(ct);
|
||||
printf(")");
|
||||
}
|
||||
|
||||
/*
|
||||
* Many realtime clocks store the year as 2-digit BCD; pivot on 70 to
|
||||
* determine century. Some clocks have a "century bit" and drivers do
|
||||
* year += 100, so interpret values between 70-199 as relative to 1900.
|
||||
*/
|
||||
year = ct->year;
|
||||
if (year < 70)
|
||||
year += 2000;
|
||||
else if (year < 200)
|
||||
year += 1900;
|
||||
|
||||
/* Sanity checks. */
|
||||
if (ct->mon < 1 || ct->mon > 12 || ct->day < 1 ||
|
||||
ct->day > days_in_month(year, ct->mon) ||
|
||||
ct->hour > 23 || ct->min > 59 || ct->sec > 59 ||
|
||||
ct->hour > 23 || ct->min > 59 || ct->sec > 59 || year < 1970 ||
|
||||
(sizeof(time_t) == 4 && year > 2037)) { /* time_t overflow */
|
||||
if (ct_debug)
|
||||
printf(" = EINVAL\n");
|
||||
|
Loading…
Reference in New Issue
Block a user