On Wed, Jul 24, 2024 at 11:50:10PM +0200, Stefano
Brivio wrote:
[...]
+/**
+ * logtime_fmt_and_arg() - Build format and arguments to print relative log time
+ * @x: Current timestamp
+ */
+#define logtime_fmt_and_arg(x) \
+ "%lli.%04lli", \
+ ((long long int)(x)->tv_sec - log_start.tv_sec), \
+ (((long long int)(x)->tv_nsec - log_start.tv_nsec) / (100L * 1000))
This doesn't look right. If x->tv_nsec - log_start.tv_nsec is
negative it will produce weird results. Instead you need more complex
logic to carry a sufficient difference in the nsec over into the
seconds difference.
Oh, oops, of course.
I was hoping to recycle this from the Linux kernel, where we have
timespec_sub(), but that implementation looks a bit too complicated for
my taste. I'm adding something simpler now.
--
Stefano