6 #include <linux/types.h>
8 #define _DEFUN(a,b,c) a(c)
14 #define SECSPERMIN 60L
15 #define MINSPERHOUR 60L
16 #define HOURSPERDAY 24L
17 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
18 #define SECSPERDAY (SECSPERHOUR * HOURSPERDAY)
20 #define MONSPERYEAR 12
22 #define YEAR_BASE 1900
23 #define EPOCH_YEAR 1970
26 #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
29 /* Used by other time functions. */
31 int tm_sec; /* Seconds. [0-60] (1 leap second) */
32 int tm_min; /* Minutes. [0-59] */
33 int tm_hour; /* Hours. [0-23] */
34 int tm_mday; /* Day. [1-31] */
35 int tm_mon; /* Month. [0-11] */
36 int tm_year; /* Year - 1900. */
37 int tm_wday; /* Day of week. [0-6] */
38 int tm_yday; /* Days in year.[0-365] */
39 int tm_isdst; /* DST. [-1/0/1]*/
42 long int tm_gmtoff; /* Seconds east of UTC. */
43 __const char *tm_zone; /* Timezone abbreviation. */
45 long int __tm_gmtoff; /* Seconds east of UTC. */
46 __const char *__tm_zone; /* Timezone abbreviation. */
51 _DEFUN (asctime_r, (tim_p, result),
52 _CONST struct tm *tim_p _AND
55 static _CONST char day_name[7][3] = {
56 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
58 static _CONST char mon_name[12][3] = {
59 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
60 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
63 sprintf (result, "%.3s %.3s %.2d %.2d:%.2d:%.2d %d\n",
64 day_name[tim_p->tm_wday],
65 mon_name[tim_p->tm_mon],
66 tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min,
67 tim_p->tm_sec, 1900 + tim_p->tm_year);
71 static inline struct tm *
72 _DEFUN (localtime_r, (tim_p, res),
73 _CONST time_t * tim_p _AND
76 static _CONST int mon_lengths[2][MONSPERYEAR] = {
77 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
78 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
81 static _CONST int year_lengths[2] = {
91 days = ((long) *tim_p) / SECSPERDAY;
92 rem = ((long) *tim_p) % SECSPERDAY;
99 /* compute hour, min, and sec */
100 res->tm_hour = (int) (rem / SECSPERHOUR);
102 res->tm_min = (int) (rem / SECSPERMIN);
103 res->tm_sec = (int) (rem % SECSPERMIN);
105 /* compute day of week */
106 if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0)
107 res->tm_wday += DAYSPERWEEK;
109 /* compute year & day of year */
116 if (days < year_lengths[yleap])
119 days -= year_lengths[yleap];
128 days += year_lengths[yleap];
132 res->tm_year = y - YEAR_BASE;
134 ip = mon_lengths[yleap];
135 for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon)
136 days -= ip[res->tm_mon];
137 res->tm_mday = days + 1;
139 /* set daylight saving time flag */
146 _DEFUN (ctime_r, (tim_p, result),
147 _CONST time_t * tim_p _AND
152 return asctime_r (localtime_r (tim_p, &tm), result);
155 /* for compatibility with linux code */
156 typedef __s64 time64_t;
158 #ifdef CONFIG_LIB_DATE
159 time64_t mktime64(const unsigned int year, const unsigned int mon,
160 const unsigned int day, const unsigned int hour,
161 const unsigned int min, const unsigned int sec);