#define time_t unsigned int struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; };
#define YEAR0 1900 #define EPOCH_YR 1970 #define SECS_DAY (24L * 60L * 60L) #define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400))) #define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365) #define FIRSTSUNDAY(timp) (((timp)->tm_yday - (timp)->tm_wday + 420) % 7) #define FIRSTDAYOF(timp) (((timp)->tm_wday - (timp)->tm_yday + 420) % 7)
#define TIME_MAX 2147483647L
int _daylight = 0; // Non-zero if daylight savings time is used
long _dstbias = 0; // Offset for Daylight Saving Time
long _timezone = 0; // Difference in seconds between GMT and local time
char *_tzname[2] = {"GMT", "GMT"}; // Standard/daylight savings time zone names
const char *_days[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
const char *_days_abbrev[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
const char *_months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
const char *_months_abbrev[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
const int _ytab[2][12] = { {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} };
struct tm *my_gmtime_r(const time_t *timer, struct tm *tmbuf) { time_t time = *timer; unsigned long dayclock, dayno; int year = EPOCH_YR;
dayclock = (unsigned long) time % SECS_DAY; dayno = (unsigned long) time / SECS_DAY;
tmbuf->tm_sec = dayclock % 60; tmbuf->tm_min = (dayclock % 3600) / 60; tmbuf->tm_hour = dayclock / 3600; tmbuf->tm_wday = (dayno + 4) % 7; // Day 0 was a thursday
while (dayno >= (unsigned long) YEARSIZE(year)) { dayno -= YEARSIZE(year); year++; } tmbuf->tm_year = year - YEAR0; tmbuf->tm_yday = dayno; tmbuf->tm_mon = 0; while (dayno >= (unsigned long) _ytab[LEAPYEAR(year)][tmbuf->tm_mon]) { dayno -= _ytab[LEAPYEAR(year)][tmbuf->tm_mon]; tmbuf->tm_mon++; } tmbuf->tm_mday = dayno + 1; tmbuf->tm_isdst = 0;
return tmbuf; }
struct tm *my_gmtime(const time_t *timer) { struct tm *tmbuf = (struct tm *)kmalloc(sizeof(struct tm *), GFP_ATOMIC); return my_gmtime_r(timer, tmbuf); }
|