1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 16:27:35 +00:00

LibC: Add ctime_r() and asctime_r() implementations

Need this for a port of FIO (Flexible IO Tester)
https://fio.readthedocs.io/
This commit is contained in:
Brian Gianforcaro 2021-04-19 22:20:13 -07:00 committed by Linus Groh
parent 8124719c3d
commit 440b81deba
2 changed files with 16 additions and 1 deletions

View file

@ -84,6 +84,12 @@ char* ctime(const time_t* t)
return asctime(localtime(t)); return asctime(localtime(t));
} }
char* ctime_r(const time_t* t, char* buf)
{
struct tm tm_buf;
return asctime_r(localtime_r(t, &tm_buf), buf);
}
static const int __seconds_per_day = 60 * 60 * 24; static const int __seconds_per_day = 60 * 60 * 24;
static void time_to_tm(struct tm* tm, time_t t) static void time_to_tm(struct tm* tm, time_t t)
@ -180,7 +186,14 @@ struct tm* gmtime_r(const time_t* t, struct tm* tm)
char* asctime(const struct tm* tm) char* asctime(const struct tm* tm)
{ {
static char buffer[69]; static char buffer[69];
strftime(buffer, sizeof buffer, "%a %b %e %T %Y", tm); return asctime_r(tm, buffer);
}
char* asctime_r(const struct tm* tm, char* buffer)
{
// Spec states buffer must be at least 26 bytes.
constexpr size_t assumed_len = 26;
strftime(buffer, assumed_len, "%a %b %e %T %Y", tm);
return buffer; return buffer;
} }

View file

@ -57,8 +57,10 @@ time_t mktime(struct tm*);
time_t timegm(struct tm*); time_t timegm(struct tm*);
time_t time(time_t*); time_t time(time_t*);
char* ctime(const time_t*); char* ctime(const time_t*);
char* ctime_r(const time_t* tm, char* buf);
void tzset(); void tzset();
char* asctime(const struct tm*); char* asctime(const struct tm*);
char* asctime_r(const struct tm*, char* buf);
#define CLOCKS_PER_SEC 1000 #define CLOCKS_PER_SEC 1000
clock_t clock(); clock_t clock();