2021-11-07 20:29:12 +01:00
|
|
|
#include "stddef.h"
|
2021-06-09 05:17:46 +02:00
|
|
|
#include <errno.h>
|
2022-04-15 11:00:55 +02:00
|
|
|
#include <stdio.h>
|
2021-06-09 05:17:46 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2022-04-15 11:00:55 +02:00
|
|
|
const char* wday_str[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
|
|
|
|
const char* mon_str[12] = { "Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
2021-06-09 05:17:46 +02:00
|
|
|
|
|
|
|
#pragma GCC push_options
|
|
|
|
#pragma GCC optimize("O0")
|
|
|
|
|
2021-11-07 20:29:12 +01:00
|
|
|
#define TIME_STR_MAX 27
|
|
|
|
|
2022-04-15 11:00:55 +02:00
|
|
|
char* asctime(const struct tm* tm)
|
|
|
|
{
|
|
|
|
if (!tm) {
|
|
|
|
__errno = EINVAL;
|
2021-11-07 20:29:12 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2022-04-15 11:00:55 +02:00
|
|
|
if (tm->tm_wday > 6 || tm->tm_wday < 0 || tm->tm_mon < 0 || tm->tm_mon > 11) {
|
2021-06-09 05:17:46 +02:00
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-11-07 20:29:12 +01:00
|
|
|
static char time_str[TIME_STR_MAX];
|
2022-04-15 11:00:55 +02:00
|
|
|
snprintf(time_str, TIME_STR_MAX - 1, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
|
2021-11-07 20:29:12 +01:00
|
|
|
wday_str[tm->tm_wday],
|
|
|
|
mon_str[tm->tm_mon],
|
|
|
|
tm->tm_mday, tm->tm_hour,
|
|
|
|
tm->tm_min, tm->tm_sec,
|
2022-04-15 11:00:55 +02:00
|
|
|
1900 + tm->tm_year);
|
2021-06-09 05:17:46 +02:00
|
|
|
return time_str;
|
|
|
|
}
|
|
|
|
#pragma GCC pop_options
|