summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/time.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2021-04-19 22:20:13 -0700
committerLinus Groh <mail@linusgroh.de>2021-04-21 08:04:52 +0200
commit440b81deba0ea9365608635687195082ca5abf80 (patch)
tree3eec020dd9d98bdf1a99e180f3a9c91bf9958eea /Userland/Libraries/LibC/time.cpp
parent8124719c3d2744edfc475155f70a286cb45e72ef (diff)
downloadserenity-440b81deba0ea9365608635687195082ca5abf80.zip
LibC: Add ctime_r() and asctime_r() implementations
Need this for a port of FIO (Flexible IO Tester) https://fio.readthedocs.io/
Diffstat (limited to 'Userland/Libraries/LibC/time.cpp')
-rw-r--r--Userland/Libraries/LibC/time.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp
index 9331bbde13..966521d994 100644
--- a/Userland/Libraries/LibC/time.cpp
+++ b/Userland/Libraries/LibC/time.cpp
@@ -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;
}