diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:25:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:25:49 +0000 |
commit | 04fc174d50fd19d6ae78fd2fd2faae221acff807 (patch) | |
tree | 23e5482ac4eb332df0fc69bf932118f0d4e42eb0 /src/iperf_formattime.c | |
parent | Adding upstream version 2.1.9+dfsg. (diff) | |
download | iperf-04fc174d50fd19d6ae78fd2fd2faae221acff807.tar.xz iperf-04fc174d50fd19d6ae78fd2fd2faae221acff807.zip |
Adding upstream version 2.2.0+dfsg.upstream/2.2.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/iperf_formattime.c')
-rw-r--r-- | src/iperf_formattime.c | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/src/iperf_formattime.c b/src/iperf_formattime.c index df65650..f0e8d1d 100644 --- a/src/iperf_formattime.c +++ b/src/iperf_formattime.c @@ -50,51 +50,53 @@ #include "iperf_formattime.h" inline void iperf_formattime (char *timestr, int buflen, struct timeval timestamp, bool prec_ms, bool utc_time, enum TimeFormatType ftype) { - struct tm ts ; - ts = (utc_time ? *gmtime(×tamp.tv_sec) : *localtime(×tamp.tv_sec)); - switch (ftype) { - case YearThruSec: - strftime(timestr, buflen, "%Y-%m-%d %H:%M:%S", &ts); - if (prec_ms) { + if (buflen > 0) { + struct tm ts ; + ts = (utc_time ? *gmtime(×tamp.tv_sec) : *localtime(×tamp.tv_sec)); + switch (ftype) { + case YearThruSec: + strftime(timestr, buflen, "%Y-%m-%d %H:%M:%S", &ts); + if (prec_ms) { + int currlen = strlen(timestr); + if (currlen > 5) { + snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); + } + } + break; + case YearThruSecTZ: + strftime(timestr, buflen, "%Y-%m-%d %H:%M:%S", &ts); int currlen = strlen(timestr); - if (currlen > 5) { - snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); + if (prec_ms) { + if (currlen > 5) { + snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); + currlen = strlen(timestr); + } } - } - break; - case YearThruSecTZ: - strftime(timestr, buflen, "%Y-%m-%d %H:%M:%S", &ts); - int currlen = strlen(timestr); - if (prec_ms) { - if (currlen > 5) { - snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); - currlen = strlen(timestr); + if ((buflen - currlen) > 5) { + strftime((timestr + currlen), (buflen - currlen), " (%Z)", &ts); } - } - if ((buflen - currlen) > 5) { - strftime((timestr + currlen), (buflen - currlen), " (%Z)", &ts); - } - break; - case CSV: - strftime(timestr, buflen, "%Y%m%d%H%M%S", &ts); - if (prec_ms) { - int currlen = strlen(timestr); - if (currlen > 5) { - snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); + break; + case CSV: + strftime(timestr, buflen, "%Y%m%d%H%M%S", &ts); + if (prec_ms) { + int currlen = strlen(timestr); + if (currlen > 5) { + snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); + } } - } - break; - case CSVTZ: - strftime(timestr, buflen, "%z:%Y%m%d%H%M%S", &ts); - if (prec_ms) { - int currlen = strlen(timestr); - if (currlen > 5) { - snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); + break; + case CSVTZ: + strftime(timestr, buflen, "%z:%Y%m%d%H%M%S", &ts); + if (prec_ms) { + int currlen = strlen(timestr); + if (currlen > 5) { + snprintf((timestr + currlen), 5, ".%.3d", (int) (timestamp.tv_usec/1000)); + } } + break; + default: + FAIL_exit(1, "iperf_formattime program error"); } - break; - default: - FAIL_exit(1, "iperf_formattime program error"); + timestr[buflen - 1] = '\0'; // make sure string is null terminated } - timestr[buflen - 1] = '\0'; // make sure string is null terminated } |