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;
96 while (rem >= SECSPERDAY)
102 /* compute hour, min, and sec */
103 res->tm_hour = (int) (rem / SECSPERHOUR);
105 res->tm_min = (int) (rem / SECSPERMIN);
106 res->tm_sec = (int) (rem % SECSPERMIN);
108 /* compute day of week */
109 if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0)
110 res->tm_wday += DAYSPERWEEK;
112 /* compute year & day of year */
119 if (days < year_lengths[yleap])
122 days -= year_lengths[yleap];
131 days += year_lengths[yleap];
135 res->tm_year = y - YEAR_BASE;
137 ip = mon_lengths[yleap];
138 for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon)
139 days -= ip[res->tm_mon];
140 res->tm_mday = days + 1;
142 /* set daylight saving time flag */
149 _DEFUN (ctime_r, (tim_p, result),
150 _CONST time_t * tim_p _AND
155 return asctime_r (localtime_r (tim_p, &tm), result);