2021-11-07 20:29:12 +01:00
|
|
|
#include "stddef.h"
|
2021-06-09 05:17:46 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
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"};
|
|
|
|
|
|
|
|
#pragma GCC push_options
|
|
|
|
#pragma GCC optimize("O0")
|
|
|
|
|
2021-11-07 20:29:12 +01:00
|
|
|
#define TIME_STR_MAX 27
|
|
|
|
|
2021-06-09 05:17:46 +02:00
|
|
|
char *asctime(const struct tm *tm){
|
2021-11-07 20:29:12 +01:00
|
|
|
if(!tm){
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
snprintf(time_str, TIME_STR_MAX-1, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
|
|
|
|
wday_str[tm->tm_wday],
|
|
|
|
mon_str[tm->tm_mon],
|
|
|
|
tm->tm_mday, tm->tm_hour,
|
|
|
|
tm->tm_min, tm->tm_sec,
|
|
|
|
1900 + tm->tm_year
|
2021-06-09 05:17:46 +02:00
|
|
|
);
|
|
|
|
return time_str;
|
|
|
|
}
|
|
|
|
#pragma GCC pop_options
|