FreeBSD/sys/dev/ips/ips_commands.c
/* Simplified localtime to provide timevalues for ffdc.
 * Taken from libc/stdtime/localtime.c
 */
Simplified localtime to provide timevalues for ffdc.
Simplified localtime to provide timevalues for ffdc .
void static ips_ffdc_settime(ips_adapter_ffdc_cmd *command, time_t sctime)
{
	long	days, rem, y;
	int	yleap, *ip, month;
	int	year_lengths[2] = { IPS_DAYSPERNYEAR, IPS_DAYSPERLYEAR };
	int	mon_lengths[2][IPS_MONSPERYEAR] = {
		{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
		{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
	};
	days = sctime / IPS_SECSPERDAY;
	rem  = sctime % IPS_SECSPERDAY;
	command->hour = rem / IPS_SECSPERHOUR;
	rem           = rem % IPS_SECSPERHOUR;
	command->minute = rem / IPS_SECSPERMIN;
	command->second = rem % IPS_SECSPERMIN;
	y = IPS_EPOCH_YEAR;
	while (days < 0 || days >= (long) year_lengths[yleap = ips_isleap(y)]) {
		long    newy;
		newy = y + days / IPS_DAYSPERNYEAR;
		if (days < 0)
			--newy;
		days -= (newy - y) * IPS_DAYSPERNYEAR +
			IPS_LEAPS_THRU_END_OF(newy - 1) -
			IPS_LEAPS_THRU_END_OF(y - 1);
		y = newy;
	}
	command->yearH = y / 100;
	command->yearL = y % 100;
	ip = mon_lengths[yleap];
	for(month = 0; days >= (long) ip[month]; ++month)
		days = days - (long) ip[month];
	command->month = month + 1;
	command->day = days + 1;
}
void static ips_ffdc_settime ( ips_adapter_ffdc_cmd * command , time_t sctime ) { long days , rem , y ; int yleap , * ip , month ; int year_lengths [ 2 ] = { IPS_DAYSPERNYEAR , IPS_DAYSPERLYEAR } ; int mon_lengths [ 2 ] [ IPS_MONSPERYEAR ] = { { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } , { 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } } ; days = sctime / IPS_SECSPERDAY ; rem = sctime % IPS_SECSPERDAY ; command -> hour = rem / IPS_SECSPERHOUR ; rem = rem % IPS_SECSPERHOUR ; command -> minute = rem / IPS_SECSPERMIN ; command -> second = rem % IPS_SECSPERMIN ; y = IPS_EPOCH_YEAR ; while ( days < 0 || days >= ( long ) year_lengths [ yleap = ips_isleap ( y ) ] ) { long newy ; newy = y + days / IPS_DAYSPERNYEAR ; if ( days < 0 ) -- newy ; days -= ( newy - y ) * IPS_DAYSPERNYEAR + IPS_LEAPS_THRU_END_OF ( newy - 1 ) - IPS_LEAPS_THRU_END_OF ( y - 1 ) ; y = newy ; } command -> yearH = y / 100 ; command -> yearL = y % 100 ; ip = mon_lengths [ yleap ] ; for ( month = 0 ; days >= ( long ) ip [ month ] ; ++ month ) days = days - ( long ) ip [ month ] ; command -> month = month + 1 ; command -> day = days + 1 ; }
Simplified localtime to provide timevalues for ffdc.
Simplified localtime to provide timevalues for ffdc .