mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:07:34 +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:
parent
8124719c3d
commit
440b81deba
2 changed files with 16 additions and 1 deletions
|
@ -84,6 +84,12 @@ char* ctime(const time_t* 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 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue