5 #include <linux/types.h>
7 #define _DEFUN(a,b,c) a(c)
13 #define SECSPERMIN 60L
14 #define MINSPERHOUR 60L
15 #define HOURSPERDAY 24L
16 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
17 #define SECSPERDAY (SECSPERHOUR * HOURSPERDAY)
19 #define MONSPERYEAR 12
21 #define YEAR_BASE 1900
22 #define EPOCH_YEAR 1970
25 #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
28 /* Used by other time functions. */
30 int tm_sec; /* Seconds. [0-60] (1 leap second) */
31 int tm_min; /* Minutes. [0-59] */
32 int tm_hour; /* Hours. [0-23] */
33 int tm_mday; /* Day. [1-31] */
34 int tm_mon; /* Month. [0-11] */
35 int tm_year; /* Year - 1900. */
36 int tm_wday; /* Day of week. [0-6] */
37 int tm_yday; /* Days in year.[0-365] */
38 int tm_isdst; /* DST. [-1/0/1]*/
41 long int tm_gmtoff; /* Seconds east of UTC. */
42 __const char *tm_zone; /* Timezone abbreviation. */
44 long int __tm_gmtoff; /* Seconds east of UTC. */
45 __const char *__tm_zone; /* Timezone abbreviation. */
50 _DEFUN (asctime_r, (tim_p, result),
51 _CONST struct tm *tim_p _AND
54 static _CONST char day_name[7][3] = {
55 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
57 static _CONST char mon_name[12][3] = {
58 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
59 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
62 sprintf (result, "%.3s %.3s %.2d %.2d:%.2d:%.2d %d\n",
63 day_name[tim_p->tm_wday],
64 mon_name[tim_p->tm_mon],
65 tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min,
66 tim_p->tm_sec, 1900 + tim_p->tm_year);
70 static inline struct tm *
71 _DEFUN (localtime_r, (tim_p, res),
72 _CONST time_t * tim_p _AND
75 static _CONST int mon_lengths[2][MONSPERYEAR] = {
76 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
77 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
80 static _CONST int year_lengths[2] = {
90 days = ((long) *tim_p) / SECSPERDAY;
91 rem = ((long) *tim_p) % SECSPERDAY;
98 /* compute hour, min, and sec */
99 res->tm_hour = (int) (rem / SECSPERHOUR);
101 res->tm_min = (int) (rem / SECSPERMIN);
102 res->tm_sec = (int) (rem % SECSPERMIN);
104 /* compute day of week */
105 if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0)
106 res->tm_wday += DAYSPERWEEK;
108 /* compute year & day of year */
115 if (days < year_lengths[yleap])
118 days -= year_lengths[yleap];
127 days += year_lengths[yleap];
131 res->tm_year = y - YEAR_BASE;
133 ip = mon_lengths[yleap];
134 for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon)
135 days -= ip[res->tm_mon];
136 res->tm_mday = days + 1;
138 /* set daylight saving time flag */
145 _DEFUN (ctime_r, (tim_p, result),
146 _CONST time_t * tim_p _AND
151 return asctime_r (localtime_r (tim_p, &tm), result);
154 /* for compatibility with linux code */
155 typedef __s64 time64_t;
157 #ifdef CONFIG_LIB_DATE
158 time64_t mktime64(const unsigned int year, const unsigned int mon,
159 const unsigned int day, const unsigned int hour,
160 const unsigned int min, const unsigned int sec);