X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=device%2Flib%2Ftime.c;h=8266ab9e69880f58a6aa8496e296e26a2d3a6897;hb=dbc215a18455517c746d70c7b53d879ded354b39;hp=dcdb09f6630a08bb6530bca3d01fed14c4e0aba8;hpb=930dd232af107d224c9385774658b178c3ad62f2;p=fw%2Fsdcc diff --git a/device/lib/time.c b/device/lib/time.c index dcdb09f6..8266ab9e 100755 --- a/device/lib/time.c +++ b/device/lib/time.c @@ -25,8 +25,6 @@ #include #include -#define FIXDS390BUG (long) - // please note that the tm structure has the years since 1900, // but time returns the seconds since 1970 @@ -39,6 +37,7 @@ #ifndef HAVE_RTC unsigned char RtcRead(struct tm *timeptr) { // no real time hardware + timeptr; // hush the compiler return 0; } #endif @@ -57,12 +56,12 @@ time_t time(time_t *timeptr) { return t; } -static code char monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; +static _CODE char monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; -static code char *month[]={"Jan","Feb","Mar","Apr","May","Jun", - "Jul","Aug","Sep","Oct","Nov","Dec"}; +_CODE char * _CODE __month[]={"Jan","Feb","Mar","Apr","May","Jun", + "Jul","Aug","Sep","Oct","Nov","Dec"}; -static code char *day[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; +_CODE char * _CODE __day[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; static char ascTimeBuffer[32]; @@ -70,18 +69,21 @@ static char ascTimeBuffer[32]; static void CheckTime(struct tm *timeptr) { // we could do some normalization here, e.g. // change 40 october to 9 november + #if !__TIME_UNSIGNED if (timeptr->tm_sec<0) timeptr->tm_sec=0; - else if (timeptr->tm_sec>59) timeptr->tm_sec=59; if (timeptr->tm_min<0) timeptr->tm_min=0; - else if (timeptr->tm_min>59) timeptr->tm_min=59; if (timeptr->tm_hour<0) timeptr->tm_hour=0; - else if (timeptr->tm_hour>23) timeptr->tm_hour=23; if (timeptr->tm_wday<0) timeptr->tm_wday=0; - else if (timeptr->tm_wday>6) timeptr->tm_wday=6; + if (timeptr->tm_mon<0) timeptr->tm_mon=0; + #endif + + if (timeptr->tm_sec>59) timeptr->tm_sec=59; + if (timeptr->tm_min>59) timeptr->tm_min=59; + if (timeptr->tm_hour>23) timeptr->tm_hour=23; + if (timeptr->tm_wday>6) timeptr->tm_wday=6; if (timeptr->tm_mday<1) timeptr->tm_mday=1; else if (timeptr->tm_mday>31) timeptr->tm_mday=31; - if (timeptr->tm_mon<0) timeptr->tm_mon=0; - else if (timeptr->tm_mon>11) timeptr->tm_mon=11; + if (timeptr->tm_mon>11) timeptr->tm_mon=11; if (timeptr->tm_year<0) timeptr->tm_year=0; } @@ -89,7 +91,7 @@ static void CheckTime(struct tm *timeptr) { char *asctime(struct tm *timeptr) { CheckTime(timeptr); sprintf (ascTimeBuffer, "%s %s %2d %02d:%02d:%02d %04d\n", - day[timeptr->tm_wday], month[timeptr->tm_mon], timeptr->tm_mday, + __day[timeptr->tm_wday], __month[timeptr->tm_mon], timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, timeptr->tm_year+1900); return ascTimeBuffer; @@ -177,28 +179,28 @@ time_t mktime(struct tm *timeptr) { CheckTime(timeptr); // seconds from 1970 till 1 jan 00:00:00 this year - seconds= FIXDS390BUG (year-1970)*60*60*24*365; + seconds= (year-1970)*(60*60*24L*365); // add extra days for leap years for (i=1970; itm_mday-1)*60*60*24; - seconds+= FIXDS390BUG timeptr->tm_hour*60*60; - seconds+= FIXDS390BUG timeptr->tm_min*60; - seconds+= FIXDS390BUG timeptr->tm_sec; + seconds+= (timeptr->tm_mday-1)*60*60*24L; + seconds+= timeptr->tm_hour*60*60L; + seconds+= timeptr->tm_min*60; + seconds+= timeptr->tm_sec; return seconds; }