summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJafar Al-Gharaibeh <jafar@atcorp.com>2024-12-21 22:59:58 -0600
committerGitHub <noreply@github.com>2024-12-21 22:59:58 -0600
commite62c2f10bc91db9c8ac867c3401b42b88ae4a1cc (patch)
treea8ed3301dd7584d5b6cdb1f43660536ac0f166a9 /lib
parent0fbda4510552234b3d6de12bacabb330ee4ecc0d (diff)
parent8f5821eb77710468b2c39e8132cd07d17448fd20 (diff)
Merge pull request #17684 from opensourcerouting/fix/json_time_no_newline
bgpd, lib: Use frrstr_time() when using ctime_r()
Diffstat (limited to 'lib')
-rw-r--r--lib/monotime.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/monotime.h b/lib/monotime.h
index f7ae1bbbe1..5e1bfe754e 100644
--- a/lib/monotime.h
+++ b/lib/monotime.h
@@ -129,6 +129,22 @@ static inline char *time_to_string(time_t ts, char *buf)
return ctime_r(&tbuf, buf);
}
+/* A wrapper for time_to_string() which removes newline at the end.
+ * This is needed for JSON outputs, where newline is not expected.
+ */
+static inline char *time_to_string_json(time_t ts, char *buf)
+{
+ size_t len;
+
+ time_to_string(ts, buf);
+ len = strlen(buf);
+
+ if (len && buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
+
+ return buf;
+}
+
/* Convert interval to human-friendly string, used in cli output e.g. */
static inline const char *frrtime_to_interval(time_t t, char *buf,
size_t buflen)