You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
378 volume VI os16<br />
Sorgenti della libreria generale 379<br />
«<br />
«<br />
105.16.1 lib/time/asctime.c<br />
Si veda la sezione 98.13.<br />
3700001 |#include <br />
3700002 |#include <br />
3700003 |#include <br />
3700004 |<br />
3700005 |//----------------------------------------------------------------------<br />
3700006 |char *<br />
3700007 |asctime (const struct tm *timeptr)<br />
3700008 |{<br />
3700009 | static char time_string[25]; // ‘Sun Jan 30 24:00:00 2111’<br />
3700010 | //<br />
3700011 | // Check argument.<br />
3700012 | //<br />
3700013 | if (timeptr == NULL)<br />
3700014 | {<br />
3700015 | return (NULL);<br />
3700016 | }<br />
3700017 | //<br />
3700018 | // Set week day.<br />
3700019 | //<br />
3700020 | switch (timeptr->tm_wday)<br />
3700021 | {<br />
3700022 | case 0:<br />
3700023 | strcpy (&time_string[0], "Sun");<br />
3700024 | break;<br />
3700025 | case 1:<br />
3700026 | strcpy (&time_string[0], "Mon");<br />
3700027 | break;<br />
3700028 | case 2:<br />
3700029 | strcpy (&time_string[0], "Tue");<br />
3700030 | break;<br />
3700031 | case 3:<br />
3700032 | strcpy (&time_string[0], "Wed");<br />
3700033 | break;<br />
3700034 | case 4:<br />
3700035 | strcpy (&time_string[0], "Thu");<br />
3700036 | break;<br />
3700037 | case 5:<br />
3700038 | strcpy (&time_string[0], "Fri");<br />
3700039 | break;<br />
3700040 | case 6:<br />
3700041 | strcpy (&time_string[0], "Sat");<br />
3700042 | break;<br />
3700043 | default:<br />
3700044 | strcpy (&time_string[0], "Err");<br />
3700045 | }<br />
3700046 | //<br />
3700047 | // Set month.<br />
3700048 | //<br />
3700049 | switch (timeptr->tm_mon)<br />
3700050 | {<br />
3700051 | case 1:<br />
3700052 | strcpy (&time_string[3], " Jan");<br />
3700053 | break;<br />
3700054 | case 2:<br />
3700055 | strcpy (&time_string[3], " Feb");<br />
3700056 | break;<br />
3700057 | case 3:<br />
3700058 | strcpy (&time_string[3], " Mar");<br />
3700059 | break;<br />
3700060 | case 4:<br />
3700061 | strcpy (&time_string[3], " Apr");<br />
3700062 | break;<br />
3700063 | case 5:<br />
3700064 | strcpy (&time_string[3], " May");<br />
3700065 | break;<br />
3700066 | case 6:<br />
3700067 | strcpy (&time_string[3], " Jun");<br />
3700068 | break;<br />
3700069 | case 7:<br />
3700070 | strcpy (&time_string[3], " Jul");<br />
3700071 | break;<br />
3700072 | case 8:<br />
3700073 | strcpy (&time_string[3], " Aug");<br />
3700074 | break;<br />
3700075 | case 9:<br />
3700076 | strcpy (&time_string[3], " Sep");<br />
3700077 | break;<br />
3700078 | case 10:<br />
3700079 | strcpy (&time_string[3], " Oct");<br />
3700080 | break;<br />
3700081 | case 11:<br />
3700082 | strcpy (&time_string[3], " Nov");<br />
3700083 | break;<br />
3700084 | case 12:<br />
3700085 | strcpy (&time_string[3], " Dec");<br />
3700086 | break;<br />
3700087 | default:<br />
3700088 | strcpy (&time_string[3], " Err");<br />
3700089 | }<br />
3700090 | //<br />
3700091 | // Set day of month, hour, minute, second and year.<br />
3700092 | //<br />
3700093 | sprintf (&time_string[7], " %2i %2i:%2i:%2i %4i",<br />
3700094 | timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min,<br />
3700095 | timeptr->tm_sec, timeptr->tm_year);<br />
3700096 | //<br />
3700097 | //<br />
3700098 | //<br />
3700099 | return (&time_string[0]);<br />
3700100 |}<br />
105.16.2 lib/time/clock.c<br />
Si veda la sezione 97.6.<br />
3710001 |#include <br />
3710002 |#include <br />
3710003 |//----------------------------------------------------------------------<br />
3710004 |clock_t<br />
3710005 |clock (void)<br />
3710006 |{<br />
3710007 | sysmsg_clock_t msg;<br />
3710008 | msg.ret = 0;<br />
3710009 | sys (SYS_CLOCK, &msg, (sizeof msg));<br />
3710010 | return (msg.ret);<br />
3710011 |}<br />
3710012 |<br />
105.16.3 lib/time/gmtime.c<br />
Si veda la sezione 98.13.<br />
3720001 |#include <br />
3720002 |//----------------------------------------------------------------------<br />
3720003 |static int leap_year (int year);<br />
3720004 |//----------------------------------------------------------------------<br />
3720005 |struct tm *<br />
3720006 |gmtime (const time_t *timer)<br />
3720007 |{<br />
3720008 | static struct tm tms;<br />
3720009 | int loop;<br />
3720010 | unsigned int remainder;<br />
3720011 | unsigned int days;<br />
3720012 | //<br />
3720013 | // Check argument.<br />
3720014 | //<br />
3720015 | if (timer == NULL)<br />
3720016 | {<br />
3720017 | return (NULL);<br />
3720018 | }<br />
3720019 | //<br />
3720020 | // Days since epoch. There are 86400 seconds per day.<br />
3720021 | // At the moment, the field ‘tm_yday’ will contain<br />
3720022 | // all days since epoch.<br />
3720023 | //<br />
3720024 | days = *timer / 86400L;<br />
3720025 | remainder = *timer % 86400L;<br />
3720026 | //<br />
3720027 | // Minutes, after full days.<br />
3720028 | //<br />
3720029 | tms.tm_min = remainder / 60U;<br />
3720030 | //<br />
3720031 | // Seconds, after full minutes.<br />
3720032 | //<br />
3720033 | tms.tm_sec = remainder % 60U;<br />
3720034 | //<br />
3720035 | // Hours, after full days.<br />
3720036 | //<br />
3720037 | tms.tm_hour = tms.tm_min / 60;<br />
3720038 | //<br />
3720039 | // Minutes, after full hours.<br />
3720040 | //<br />
3720041 | tms.tm_min = tms.tm_min % 60;<br />
3720042 | //<br />
3720043 | // Find the week day. Must remove some days to align the<br />
3720044 | // calculation. So: the week days of the first week of 1970<br />
3720045 | // are not valid! After 1970-01-04 calculations are right.<br />
3720046 | //<br />
3720047 | tms.tm_wday = (days - 3) % 7;<br />
3720048 | //<br />
3720049 | // Find the year: the field ‘tm_yday’ will be reduced to the days<br />
3720050 | // of current year.<br />
3720051 | //<br />
3720052 | for (tms.tm_year = 1970; days > 0; tms.tm_year++)<br />
3720053 | {<br />
3720054 | if (leap_year (tms.tm_year))<br />
3720055 | {<br />
3720056 | if (days >= 366)<br />
3720057 | {<br />
3720058 | days -= 366;<br />
3720059 | continue;<br />
3720060 | }<br />
3720061 | else<br />
3720062 | {<br />
3720063 | break;<br />
3720064 | }<br />
3720065 | }<br />
3720066 | else<br />
3720067 | {<br />
3720068 | if (days >= 365)<br />
3720069 | {<br />
3720070 | days -= 365;<br />
3720071 | continue;<br />
3720072 | }<br />
3720073 | else<br />
3720074 | {<br />
3720075 | break;<br />
3720076 | }<br />
3720077 | }<br />
3720078 | }<br />
3720079 | //<br />
3720080 | // Day of the year.<br />
3720081 | //<br />
3720082 | tms.tm_yday = days + 1;<br />
3720083 | //<br />
3720084 | // Find the month.<br />
3720085 | //<br />
3720086 | tms.tm_mday = days + 1;<br />
3720087 | //<br />
3720088 | for (tms.tm_mon = 0, loop = 1; tms.tm_mon = 31)<br />
3720102 | {<br />
3720103 | tms.tm_mday -= 31;<br />
3720104 | }<br />
3720105 | else<br />
3720106 | {<br />
«