aboutsummaryrefslogtreecommitdiffstats
path: root/libpatch_create_timestamp_frac_string.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
committerMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
commitae850b1ac755f471beac4dbfef4654fe3fbaaae9 (patch)
tree319e7f7f1b99cd1ee75e100f0a29b0f7c827ccea /libpatch_create_timestamp_frac_string.c
downloadlibpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.gz
libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.bz2
libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.xz
First commitHEADmaster
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libpatch_create_timestamp_frac_string.c')
-rw-r--r--libpatch_create_timestamp_frac_string.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/libpatch_create_timestamp_frac_string.c b/libpatch_create_timestamp_frac_string.c
new file mode 100644
index 0000000..18b8090
--- /dev/null
+++ b/libpatch_create_timestamp_frac_string.c
@@ -0,0 +1,21 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+size_t
+libpatch_create_timestamp_frac_string(char *buf, size_t bufsize, const struct tm *tm,
+ const char *frac, int zone, enum libpatch_style style)
+{
+ uintmax_t subseconds = 0, digit;
+ unsigned decimals = 0;
+ if (frac) {
+ for (;; frac++) {
+ digit = (uintmax_t)*frac - (uintmax_t)'0';
+ if (digit > 9 || subseconds > (UINTMAX_MAX - digit) / 10U)
+ break;
+ subseconds = subseconds * 10U + digit;
+ decimals += 1;
+ }
+ }
+ return libpatch_create_timestamp(buf, bufsize, tm, subseconds, decimals, decimals, zone, style);
+}