Save Log to File *******************************************************************/ bool log_save ( char *log_file, char *ErrMsg) { FILE *p; p = fopen(log_file, "wb"); if ( p == NULL ) return false; fprintf(p, "[Err]: %s\n", ErrMsg); /* Write ErrMsg to File. */ fclose(p); return true; } /******************************************************************* * Is Leap Year *******************************************************************/ bool is_leap_year ( int year ) { return ( ((year%100==0) && (year%400==0)) || ((year%100!=0) && (year%4==0)) ); } /******************************************************************* * Which Day with Year+Mon+day Specified *******************************************************************/ int which_day (int year, int mon, int day) { static int mdays[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 }; int i, days = day; for (i=0; i { days += mdays[i]; } if (mon>2) { if ( is_leap_year(year) ) ++days; } return days; } /******************************************************************* * Check CPU endian type *******************************************************************/ bool is_little_endian( void ) { union w{ int a; char b; } c; c.a = 1; return ( c.b == 1 ); } #endif /* __tsdk_h__ */ 摘自 tody_guo的专栏
|