4 #include <linux/types.h>
6 #define _DEFUN(a,b,c) a(c)
12 #define SECSPERMIN 60L
13 #define MINSPERHOUR 60L
14 #define HOURSPERDAY 24L
15 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
16 #define SECSPERDAY (SECSPERHOUR * HOURSPERDAY)
18 #define MONSPERYEAR 12
20 #define YEAR_BASE 1900
21 #define EPOCH_YEAR 1970
24 #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
27 /* Used by other time functions. */
29 int tm_sec; /* Seconds. [0-60] (1 leap second) */
30 int tm_min; /* Minutes. [0-59] */
31 int tm_hour; /* Hours. [0-23] */
32 int tm_mday; /* Day. [1-31] */
33 int tm_mon; /* Month. [0-11] */
34 int tm_year; /* Year - 1900. */
35 int tm_wday; /* Day of week. [0-6] */
36 int tm_yday; /* Days in year.[0-365] */
37 int tm_isdst; /* DST. [-1/0/1]*/
40 long int tm_gmtoff; /* Seconds east of UTC. */
41 __const char *tm_zone; /* Timezone abbreviation. */
43 long int __tm_gmtoff; /* Seconds east of UTC. */
44 __const char *__tm_zone; /* Timezone abbreviation. */
49 _DEFUN (asctime_r, (tim_p, result),
50 _CONST struct tm *tim_p _AND
53 static _CONST char day_name[7][3] = {
54 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
56 static _CONST char mon_name[12][3] = {
57 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
58 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
61 sprintf (result, "%.3s %.3s %.2d %.2d:%.2d:%.2d %d\n",
62 day_name[tim_p->tm_wday],
63 mon_name[tim_p->tm_mon],
64 tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min,
65 tim_p->tm_sec, 1900 + tim_p->tm_year);
69 static inline struct tm *
70 _DEFUN (localtime_r, (tim_p, res),
71 _CONST time_t * tim_p _AND
74 static _CONST int mon_lengths[2][MONSPERYEAR] = {
75 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
76 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
79 static _CONST int year_lengths[2] = {
89 days = ((long) *tim_p) / SECSPERDAY;
90 rem = ((long) *tim_p) % SECSPERDAY;
97 /* compute hour, min, and sec */
98 res->tm_hour = (int) (rem / SECSPERHOUR);
100 res->tm_min = (int) (rem / SECSPERMIN);
101 res->tm_sec = (int) (rem % SECSPERMIN);
103 /* compute day of week */
104 if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0)
105 res->tm_wday += DAYSPERWEEK;
107 /* compute year & day of year */
114 if (days < year_lengths[yleap])
117 days -= year_lengths[yleap];
126 days += year_lengths[yleap];
130 res->tm_year = y - YEAR_BASE;
132 ip = mon_lengths[yleap];
133 for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon)
134 days -= ip[res->tm_mon];
135 res->tm_mday = days + 1;
137 /* set daylight saving time flag */
144 _DEFUN (ctime_r, (tim_p, result),
145 _CONST time_t * tim_p _AND
150 return asctime_r (localtime_r (tim_p, &tm), result);