⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 check_y2k.c

📁 网络时间协议NTP 源码 版本v4.2.0b 该源码用于linux平台下
💻 C
📖 第 1 页 / 共 2 页
字号:
		"  %4d %2d *** ERROR\n", year, LeapSw );	    break;	}    }  }       puts( " libparse/parse.c" );  {     long Days1970;	/* days from 1900 to 1970 */    struct ParseTime	/* womp up a test structure to all cut/paste code */    {       int   year;    } Clock_Time, *clock_time;    clock_time = &Clock_Time;	/* first test this #define */#define days_per_year(x)  ((x) % 4 ? 365 : ((x % 400) ? ((x % 100) ? 366 : 365) : 366))    for ( year = 1400; year <= 2200; year++ )    {	int  LeapSw;	int  DayCnt;	LeapSw = GoodLeap(year);	DayCnt = (int)days_per_year(year);	if ( ( LeapSw ? 366 : 365 ) != DayCnt )	{	    Error(year);	    fprintf( stdout, 		    "  days_per_year() %4d %2d %3d *** ERROR\n", 		    year, LeapSw, DayCnt );	    break;	}    }    /* test (what is now julian0) calculations */    Days1970 = Days( 1970 );	/* get days since 1970 using a known good */    for ( year = 1970; year < yearend; year++ )    {					unsigned long t;	long DaysYear ;	clock_time->year = year;	/* here is the code we are testing, cut and pasted out of the source */#if 0		/* old BUGGY code that has Y2K (and many other) failures */	    /* ghealton: this logic FAILED with great frequency when run	     * over a period of time, including for year 2000. True, it	     * had more successes than failures, but that's not really good	     * enough for critical time distribution software.	     * It is so awful I wonder if it has had a history of failure 	     * and fixes? */        t =  (clock_time->year - 1970) * 365;        t += (clock_time->year >> 2) - (1970 >> 2);        t -= clock_time->year / 100 - 1970 / 100;        t += clock_time->year / 400 - 1970 / 400;		/* (immediate feare of rounding errors on integer		 * **divisions proved well founded) */#else	/* my replacement, based on Days() above */	t = julian0(year) - julian0(1970);#endif	/* compare result in t against trusted calculations */	DaysYear = Days( year );	/* get days to this year */	if ( t != DaysYear - Days1970 )	{	    Error(year);	    fprintf( stdout, 		"  %4d 1970=%-8ld %4d=%-8ld %-3ld  t=%-8ld  *** ERROR ***\n",		  year,      (long)Days1970,				 year,				     (long)DaysYear,					   (long)(DaysYear - Days1970),						   (long)t );	}    }#if 1		/* { */   {    debug = 1;			/* enable debugging */    for ( year = 1970; year < yearend; year++ )    {		/* (limited by theory unix 2038 related bug lives by, but		 * ends in yearend) */	clocktime_t  ct;	time_t	     Observed;	time_t	     Expected;	u_long       Flag;	unsigned long t;	ct.day = 1;	ct.month = 1;	ct.year = year;	ct.hour = ct.minute = ct.second = ct.usecond = 0;	ct.utcoffset = 0;	ct.utctime = 0;	ct.flags = 0;	Flag = 0; 	Observed = parse_to_unixtime( &ct, &Flag );	if ( ct.year != year )	{	    fprintf( stdout, 	       "%04d: parse_to_unixtime(,%d) CORRUPTED ct.year: was %d\n",	       (int)year, (int)Flag, (int)ct.year );	    Error(year);	    break;	}	t = julian0(year) - julian0(1970);	/* Julian day from 1970 */	Expected = t * 24 * 60 * 60;	if ( Observed != Expected  ||  Flag )	{   /* time difference */	    fprintf( stdout, 	       "%04d: parse_to_unixtime(,%d) FAILURE: was=%lu s/b=%lu  (%ld)\n",	       year, (int)Flag, 	       (unsigned long)Observed, (unsigned long)Expected,	       ((long)Observed - (long)Expected) );	    Error(year);	    break;	}	if ( year >= YEAR_PIVOT+1900 )	{	    /* check year % 100 code we put into parse_to_unixtime() */	    ct.utctime = 0;	    ct.year = year % 100;	    Flag = 0;	    Observed = parse_to_unixtime( &ct, &Flag );	    if ( Observed != Expected  ||  Flag )	    {   /* time difference */		fprintf( stdout, "%04d: parse_to_unixtime(%d,%d) FAILURE: was=%lu s/b=%lu  (%ld)\n",		   year, (int)ct.year, (int)Flag, 		   (unsigned long)Observed, (unsigned long)Expected,		   ((long)Observed - (long)Expected) );		Error(year);		break;	    }	    /* check year - 1900 code we put into parse_to_unixtime() */	    ct.utctime = 0;	    ct.year = year - 1900;	    Flag = 0;	    Observed = parse_to_unixtime( &ct, &Flag );	    if ( Observed != Expected  ||  Flag )	    {   /* time difference */		fprintf( stdout, "%04d: parse_to_unixtime(%d,%d) FAILURE: was=%lu s/b=%lu  (%ld)\n",		   year, (int)ct.year, (int)Flag, 		   (unsigned long)Observed, (unsigned long)Expected,		   ((long)Observed - (long)Expected) );		Error(year);		break;	    }	}    }#endif		/* } */   }  }    puts( " libntp/caljulian.c" );  {		/* test caljulian() */    struct	calendar  ot;    u_long ntp_time;		/* NTP time */    year = year0;		/* calculate the basic year */    printf( "  starting year %04d\n", (int)year0 );    printf( "  ending year   %04d\n", (int)yearend );    ntp_time = julian0( year0 );		/* NTP starts in 1900-01-01 */#if DAY_NTP_STARTS == 693596    ntp_time -= 365;		/* BIAS required for successful test */#endif    if ( DAY_NTP_STARTS != ntp_time )    {	Error(year);	fprintf( stdout, 		"%04d: DAY_NTP_STARTS (%ld) NOT TRUE VALUE OF %ld (%ld)\n",		(int)year0,		(long)DAY_NTP_STARTS,  (long)ntp_time,		(long)DAY_NTP_STARTS - (long)ntp_time );    }    for ( ; year < yearend; year++ )    {		/* 01-01 for the current year */	ntp_time = Days( year ) - Days( year0 );  /* days into NTP time */	ntp_time *= 24 * 60 * 60;	/* convert into seconds */	caljulian( ntp_time, &ot );	/* convert January 1 */	if ( ot.year  != year	  || ot.month != 1	  || ot.monthday != 1 )	{	    Error(year);	    fprintf( stdout, "%lu: EXPECTED %04d-01-01: FOUND %04d-%02d-%02d\n",			(unsigned long)ntp_time,			year, 			(int)ot.year, (int)ot.month, (int)ot.monthday );	    break;	}	ntp_time += (31 + 28-1) * ( 24 * 60 * 60 );	/* advance to 02-28 */	caljulian( ntp_time, &ot );	/* convert Feb 28 */	if ( ot.year  != year	  || ot.month != 2	  || ot.monthday != 28 )	{	    Error(year);	    fprintf( stdout, "%lu: EXPECTED %04d-02-28: FOUND %04d-%02d-%02d\n",			(unsigned long)ntp_time,			year, 			(int)ot.year, (int)ot.month, (int)ot.monthday );	    break;	}      {	int    m;		/* expected month */	int    d;		/* expected day */	m = isleap_4(year) ?  2 : 3;	d = isleap_4(year) ? 29 : 1;	ntp_time += ( 24 * 60 * 60 );	/* advance to the next day */	caljulian( ntp_time, &ot );	/* convert this day */	if ( ot.year  != year	  || ot.month != m	  || ot.monthday != d )	{	    Error(year);	    fprintf( stdout, "%lu: EXPECTED %04d-%02d-%02d: FOUND %04d-%02d-%02d\n",			(unsigned long)ntp_time,			year, m, d, 			(int)ot.year, (int)ot.month, (int)ot.monthday );	    break;	}      }    }  }    puts( " libntp/caltontp.c" );  {		/* test caltontp() */    struct	calendar  ot;    u_long      ntp_time;		/* NTP time */    year = year0;		/* calculate the basic year */    printf( "  starting year %04d\n", (int)year0 );    printf( "  ending year   %04d\n", (int)yearend );    for ( ; year < yearend; year++ )    {	u_long  ObservedNtp;		/* 01-01 for the current year */	ot.year = year;	ot.month = ot.monthday = 1; 	/* unused, but set anyway JIC */	ot.yearday = 1;		/* this is the magic value used by caltontp() */	ot.hour = ot.minute = ot.second = 0;	ntp_time = Days( year ) - Days( year0 );  /* days into NTP time */	ntp_time *= 24 * 60 * 60;	/* convert into seconds */	ObservedNtp = caltontp( &ot );	if ( ntp_time != ObservedNtp )	{	    Error(year);	    fprintf( stdout, "%d: EXPECTED %lu: FOUND %lu (%ld)\n",			(int)year,			(unsigned long)ntp_time, (unsigned long)ObservedNtp ,			(long)ntp_time - (long)ObservedNtp );	    break;	}	/* now call caljulian as a type of failsafe supercheck */	caljulian( ObservedNtp, &ot );	/* convert January 1 */	if ( ot.year  != year	  || ot.month != 1	  || ot.monthday != 1 )	{	    Error(year);	    fprintf( stdout, "%lu: caljulian FAILSAFE EXPECTED %04d-01-01: FOUND %04d-%02d-%02d\n",			(unsigned long)ObservedNtp,			year, 			(int)ot.year, (int)ot.month, (int)ot.monthday );	    break;	}    }  }   if ( Warnings > 0 )       fprintf( stdout, "%d WARNINGS\n",  Warnings );   if ( Fatals > 0 )       fprintf( stdout, "%d FATAL ERRORS\n",  Fatals );   return Fatals ? 1 : 0;}							/* Y2KFixes ] */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -