summaryrefslogtreecommitdiffstats
path: root/lib/time
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:37 +0000
commitb6b00dd55e035bfbe311a527b567962ffa77ee43 (patch)
treecafc4d13785448e5a78bd40a51697ee07f07ac12 /lib/time
parentAdding debian version 1:4.13+dfsg1-5. (diff)
downloadshadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.tar.xz
shadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.zip
Merging upstream version 1:4.15.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/time')
-rw-r--r--lib/time/day_to_str.c11
-rw-r--r--lib/time/day_to_str.h51
2 files changed, 62 insertions, 0 deletions
diff --git a/lib/time/day_to_str.c b/lib/time/day_to_str.c
new file mode 100644
index 0000000..e3e4221
--- /dev/null
+++ b/lib/time/day_to_str.c
@@ -0,0 +1,11 @@
+// SPDX-FileCopyrightText: 2021-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024, Tobias Stoeckmann <tobias@stoeckmann.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "time/day_to_str.h"
+
+
+extern inline void day_to_str(size_t size, char buf[size], long day);
diff --git a/lib/time/day_to_str.h b/lib/time/day_to_str.h
new file mode 100644
index 0000000..96cec6e
--- /dev/null
+++ b/lib/time/day_to_str.h
@@ -0,0 +1,51 @@
+// SPDX-FileCopyrightText: 2021-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024, Tobias Stoeckmann <tobias@stoeckmann.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_TIME_DAY_TO_STR_H_
+#define SHADOW_INCLUDE_LIB_TIME_DAY_TO_STR_H_
+
+
+#include <config.h>
+
+#include <time.h>
+
+#include "defines.h"
+#include "sizeof.h"
+#include "string/strtcpy.h"
+
+
+#define DAY_TO_STR(str, day) day_to_str(NITEMS(str), str, day)
+
+
+inline void day_to_str(size_t size, char buf[size], long day);
+
+
+inline void
+day_to_str(size_t size, char buf[size], long day)
+{
+ time_t date;
+ struct tm tm;
+
+ if (day < 0) {
+ strtcpy(buf, "never", size);
+ return;
+ }
+
+ if (__builtin_mul_overflow(day, DAY, &date)) {
+ strtcpy(buf, "future", size);
+ return;
+ }
+
+ if (gmtime_r(&date, &tm) == NULL) {
+ strtcpy(buf, "future", size);
+ return;
+ }
+
+ if (strftime(buf, size, "%Y-%m-%d", &tm) == 0)
+ strtcpy(buf, "future", size);
+}
+
+
+#endif // include guard