timestamp formatting: always use 64-bit for timesstamp formatting.

Using C99 `unsigned long long` to format `struct timeval`'s `tv_sec`
and `tv_usec`, fix incorrect print under some 32bit platform which
 using time64.
This commit is contained in:
TyK
2023-11-28 08:30:27 +08:00
parent 97c8ccdbbf
commit ceda93bd5c
11 changed files with 58 additions and 42 deletions
+3 -3
View File
@@ -101,7 +101,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
switch (timestamp) {
case 'a': /* absolute with timestamp */
printf("(%lu.%06lu) ", tv->tv_sec, tv->tv_usec);
printf("(%llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec);
break;
case 'A': /* absolute with date */
@@ -111,7 +111,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
tm = *localtime(&tv->tv_sec);
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
printf("(%s.%06lu) ", timestring, tv->tv_usec);
printf("(%s.%06llu) ", timestring, (unsigned long long)tv->tv_usec);
}
break;
@@ -128,7 +128,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
diff.tv_sec--, diff.tv_usec += 1000000;
if (diff.tv_sec < 0)
diff.tv_sec = diff.tv_usec = 0;
printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec);
printf("(%llu.%06llu) ", (unsigned long long)diff.tv_sec, (unsigned long long)diff.tv_usec);
if (timestamp == 'd')
*last_tv = *tv; /* update for delta calculation */