Emit summaries of struct c(alender)t(ime) <-> struct timespec conversions
under bootverbose. Struct ct is used for setting/reading real time clocks and I'm about to Do Things to some of those, so a bit of preemptive debugging is in order. Remove a pointless __inline.
This commit is contained in:
parent
3b33782a3e
commit
c9ad6040dd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=178162
@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/timetc.h>
|
||||
|
||||
#define ct_debug bootverbose
|
||||
static int adjkerntz; /* local offset from GMT in seconds */
|
||||
static int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */
|
||||
int disable_rtc_set; /* disable resettodr() if != 0 */
|
||||
@ -107,7 +108,7 @@ static const int month_days[12] = {
|
||||
* ((year % 400) == 0) )
|
||||
* It is otherwise equivalent.
|
||||
*/
|
||||
static __inline int
|
||||
static int
|
||||
leapyear(int year)
|
||||
{
|
||||
int rv = 0;
|
||||
@ -123,6 +124,14 @@ leapyear(int year)
|
||||
return (rv);
|
||||
}
|
||||
|
||||
static void
|
||||
print_ct(struct clocktime *ct)
|
||||
{
|
||||
printf("[%04d-%02d-%02d %02d:%02d:%02d]",
|
||||
ct->year, ct->mon, ct->day,
|
||||
ct->hour, ct->min, ct->sec);
|
||||
}
|
||||
|
||||
int
|
||||
clock_ct_to_ts(struct clocktime *ct, struct timespec *ts)
|
||||
{
|
||||
@ -131,12 +140,21 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec *ts)
|
||||
|
||||
year = ct->year;
|
||||
|
||||
if (ct_debug) {
|
||||
printf("ct_to_ts(");
|
||||
print_ct(ct);
|
||||
printf(")");
|
||||
}
|
||||
|
||||
/* 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->year > 2037) /* time_t overflow */
|
||||
ct->year > 2037) { /* time_t overflow */
|
||||
if (ct_debug)
|
||||
printf(" = EINVAL\n");
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute days since start of time
|
||||
@ -160,6 +178,8 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec *ts)
|
||||
|
||||
ts->tv_sec = secs;
|
||||
ts->tv_nsec = ct->nsec;
|
||||
if (ct_debug)
|
||||
printf(" = %d.%09ld\n", ts->tv_sec, (long)ts->tv_nsec);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -196,6 +216,11 @@ clock_ts_to_ct(struct timespec *ts, struct clocktime *ct)
|
||||
rsec = rsec % 60;
|
||||
ct->sec = rsec;
|
||||
ct->nsec = ts->tv_nsec;
|
||||
if (ct_debug) {
|
||||
printf("ts_to_ct(%d.%09ld) = ", ts->tv_sec, (long)ts->tv_nsec);
|
||||
print_ct(ct);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user