MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / asctime_r

Function asctime_r

components/libc/compilers/common/ctime.c:247–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245RTM_EXPORT(mktime);
246
247char* asctime_r(const struct tm *t, char *buf)
248{
249 if(t == RT_NULL || buf == RT_NULL)
250 {
251 rt_set_errno(EFAULT);
252 return RT_NULL;
253 }
254
255 rt_memset(buf, RT_NULL, 26);
256
257 /* Checking input validity */
258 if ((int)rt_strlen(days) <= (t->tm_wday << 2) || (int)rt_strlen(months) <= (t->tm_mon << 2))
259 {
260 LOG_W("asctime_r: the input parameters exceeded the limit, please check it.");
261 *(int*) buf = *(int*) days;
262 *(int*) (buf + 4) = *(int*) months;
263 num2str(buf + 8, t->tm_mday);
264 if (buf[8] == '0')
265 buf[8] = ' ';
266 buf[10] = ' ';
267 num2str(buf + 11, t->tm_hour);
268 buf[13] = ':';
269 num2str(buf + 14, t->tm_min);
270 buf[16] = ':';
271 num2str(buf + 17, t->tm_sec);
272 buf[19] = ' ';
273 num2str(buf + 20, 2000 / 100);
274 num2str(buf + 22, 2000 % 100);
275 buf[24] = '\n';
276 buf[25] = '\0';
277 return buf;
278 }
279
280 /* "Wed Jun 30 21:49:08 1993\n" */
281 *(int*) buf = *(int*) (days + (t->tm_wday << 2));
282 *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2));
283 num2str(buf + 8, t->tm_mday);
284 if (buf[8] == '0')
285 buf[8] = ' ';
286 buf[10] = ' ';
287 num2str(buf + 11, t->tm_hour);
288 buf[13] = ':';
289 num2str(buf + 14, t->tm_min);
290 buf[16] = ':';
291 num2str(buf + 17, t->tm_sec);
292 buf[19] = ' ';
293 num2str(buf + 20, (t->tm_year + 1900) / 100);
294 num2str(buf + 22, (t->tm_year + 1900) % 100);
295 buf[24] = '\n';
296 buf[25] = '\0';
297 return buf;
298}
299RTM_EXPORT(asctime_r);
300
301char *asctime(const struct tm *timeptr)

Callers 2

asctimeFunction · 0.85
ctime_rFunction · 0.85

Calls 4

rt_set_errnoFunction · 0.85
rt_memsetFunction · 0.85
rt_strlenFunction · 0.85
num2strFunction · 0.85

Tested by

no test coverage detected