1 #include "ace/OS_NS_time.h"
3 #if !defined (ACE_HAS_INLINED_OSCALLS)
4 # include "ace/OS_NS_time.inl"
5 #endif /* ACE_HAS_INLINED_OSCALLS */
7 #if defined (ACE_LACKS_STRPTIME)
8 # include "ace/os_include/os_ctype.h"
9 #endif /* ACE_LACKS_STRPTIME */
11 #include "ace/OS_NS_Thread.h"
12 #include "ace/Object_Manager_Base.h"
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 ACE_OS::localtime_r (const time_t *t
, struct tm
*res
)
19 ACE_OS_TRACE ("ACE_OS::localtime_r");
20 #if defined (ACE_HAS_TR24731_2005_CRT)
21 ACE_SECURECRTCALL (localtime_s (res
, t
), struct tm
*, 0, res
);
23 #elif defined (ACE_LACKS_LOCALTIME_R)
27 struct tm
* res_ptr
= 0;
28 ACE_OSCALL (::localtime (t
), struct tm
*, res_ptr
);
37 return ace_localtime_r_helper (t
, res
);
38 #endif /* ACE_HAS_TR24731_2005_CRT */
42 ACE_OS::mktime (struct tm
*t
)
44 ACE_OS_TRACE ("ACE_OS::mktime");
45 #if defined (ACE_HAS_THREADS) && !defined (ACE_HAS_MT_SAFE_MKTIME)
47 #endif /* ACE_HAS_THREADS && ! ACE_HAS_MT_SAFE_MKTIME */
49 return std::mktime (t
);
52 #if defined (ACE_LACKS_STRPTIME)
54 ACE_OS::strptime_emulation (const char *buf
, const char *format
, struct tm
*tm
)
63 while (format
[fi
] != '\0')
70 case '%': // an escaped %
77 return const_cast<char*> (buf
+ bi
);
80 /* not supported yet: weekday via locale long/short names
81 case 'a': / * weekday via locale * /
83 case 'A': / * long/short names * /
88 case 'b': / * month via locale * /
90 case 'B': / * long/short names * /
97 case 'c': / * %x %X * /
101 /* not supported yet:
102 case 'C': / * date & time - * /
103 / * locale long format * /
107 case 'd': /* day of month (1-31) */
110 if (!ACE_OS::strptime_getnum
111 (buf
+ bi
, &tm
->tm_mday
, &bi
, &fi
, 1, 31))
112 return const_cast<char*> (buf
+ bi
);
116 case 'D': /* %m/%d/%y */
117 if (!ACE_OS::strptime_getnum
118 (buf
+ bi
, &tm
->tm_mon
, &bi
, &fi
, 1, 12))
119 return const_cast<char*> (buf
+ bi
);
125 return const_cast<char*> (buf
+ bi
);
129 if (!ACE_OS::strptime_getnum
130 (buf
+ bi
, &tm
->tm_mday
, &bi
, &fi
, 1, 31))
131 return const_cast<char*> (buf
+ bi
);
135 return const_cast<char*> (buf
+ bi
);
137 if (!ACE_OS::strptime_getnum
138 (buf
+ bi
, &tm
->tm_year
, &bi
, &fi
, 0, 99))
139 return const_cast<char*> (buf
+ bi
);
140 if (tm
->tm_year
< 69)
144 case 'H': /* hour (0-23) */
147 if (!ACE_OS::strptime_getnum
148 (buf
+ bi
, &tm
->tm_hour
, &bi
, &fi
, 0, 23))
149 return const_cast<char*> (buf
+ bi
);
152 /* not supported yet:
153 case 'I': / * hour (0-12) * /
159 case 'j': /* day of year (0-366) */
160 if (!ACE_OS::strptime_getnum
161 (buf
+ bi
, &tm
->tm_yday
, &bi
, &fi
, 1, 366))
162 return const_cast<char*> (buf
+ bi
);
167 case 'm': /* an escaped % */
168 if (!ACE_OS::strptime_getnum
169 (buf
+ bi
, &tm
->tm_mon
, &bi
, &fi
, 1, 12))
170 return const_cast<char*> (buf
+ bi
);
175 case 'M': /* minute (0-59) */
176 if (!ACE_OS::strptime_getnum
177 (buf
+ bi
, &tm
->tm_min
, &bi
, &fi
, 0, 59))
178 return const_cast<char*> (buf
+ bi
);
182 /* not supported yet:
183 case 'p': / * am or pm for locale * /
187 /* not supported yet:
188 case 'r': / * %I:%M:%S %p * /
192 case 'R': /* %H:%M */
193 if (!ACE_OS::strptime_getnum
194 (buf
+ bi
, &tm
->tm_hour
, &bi
, &fi
, 0, 23))
195 return const_cast<char*> (buf
+ bi
);
199 return const_cast<char*> (buf
+ bi
);
201 if (!ACE_OS::strptime_getnum
202 (buf
+ bi
, &tm
->tm_min
, &bi
, &fi
, 0, 59))
203 return const_cast<char*> (buf
+ bi
);
207 case 'S': /* seconds (0-61) */
208 if (!ACE_OS::strptime_getnum
209 (buf
+ bi
, &tm
->tm_sec
, &bi
, &fi
, 0, 61))
210 return const_cast<char*> (buf
+ bi
);
213 case 'T': /* %H:%M:%S */
214 if (!ACE_OS::strptime_getnum
215 (buf
+ bi
, &tm
->tm_hour
, &bi
, &fi
, 0, 23))
216 return const_cast<char*> (buf
+ bi
);
220 return const_cast<char*> (buf
+ bi
);
222 if (!ACE_OS::strptime_getnum
223 (buf
+ bi
, &tm
->tm_min
, &bi
, &fi
, 0, 59))
224 return const_cast<char*> (buf
+ bi
);
228 return const_cast<char*> (buf
+ bi
);
230 if (!ACE_OS::strptime_getnum
231 (buf
+ bi
, &tm
->tm_sec
, &bi
, &fi
, 0, 61))
232 return const_cast<char*> (buf
+ bi
);
236 case 'w': /* day of week (0=Sun-6) */
237 if (!ACE_OS::strptime_getnum
238 (buf
+ bi
, &tm
->tm_wday
, &bi
, &fi
, 0, 6))
239 return const_cast<char*> (buf
+ bi
);
243 /* not supported yet: date, based on locale
244 case 'x': / * date, based on locale * /
248 /* not supported yet:
249 case 'X': / * time, based on locale * /
253 case 'y': /* the year - 1900 (0-99) */
254 if (!ACE_OS::strptime_getnum
255 (buf
+ bi
, &tm
->tm_year
, &bi
, &fi
, 0, 99))
256 return const_cast<char*> (buf
+ bi
);
258 if (tm
->tm_year
< 69)
262 case 'Y': /* the full year (1999) */
263 if (!ACE_OS::strptime_getnum
264 (buf
+ bi
, &tm
->tm_year
, &bi
, &fi
, 0, 0))
265 return const_cast<char*> (buf
+ bi
);
270 default: /* unrecognised */
271 return const_cast<char*> (buf
+ bi
);
272 } /* switch (format[fi]) */
277 if (format
[fi
] == '%')
284 if (format
[fi
] == buf
[bi
])
290 return const_cast<char*> (buf
+ bi
);
293 } /* while (format[fi] */
295 return const_cast<char*> (buf
+ bi
);
299 ACE_OS::strptime_getnum (const char *buf
,
308 while (isdigit (buf
[i
]))
310 tmp
= (tmp
* 10) + (buf
[i
] - '0');
311 if (max
&& (tmp
> max
))
328 #endif /* ACE_LACKS_STRPTIME */
330 ACE_END_VERSIONED_NAMESPACE_DECL