X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_misc.c;h=a39f4591831ddf988f8cbcb74ab323658c74b76a;hb=96e6e88fd94af95e15d143e4a86d5a9e858d340d;hp=3bfd214c1914163bf0019a4241e52eb11a035a8c;hpb=cd6f1f9a84c17dbdf6ab320a04eae300502b898d;p=tfcrypt.git diff --git a/tfc_misc.c b/tfc_misc.c index 3bfd214..a39f459 100644 --- a/tfc_misc.c +++ b/tfc_misc.c @@ -85,11 +85,11 @@ const char *tfc_modename(int mode) void tfc_getcurtime(tfc_useconds *tx) { - struct timeval t; + struct timespec t; memset(&t, 0, sizeof(t)); - gettimeofday(&t, NULL); - *tx = (tfc_useconds)t.tv_sec * 1000000 + t.tv_usec; + clock_gettime(CLOCK_MONOTONIC, &t); + *tx = (tfc_useconds)t.tv_sec * 1000000 + (t.tv_nsec / 1000); memset(&t, 0, sizeof(t)); } @@ -108,10 +108,10 @@ char *tfc_format_time(tfc_useconds t) minutes = (secs / 60) % 60; seconds = secs % 60; - if (days > 0) sprintf(r, "%ud,%02u:%02u:%02u.%03u", days, hours, minutes, seconds, (unsigned)(dsecs / 1000)); - else if (hours > 0) sprintf(r, "%02u:%02u:%02u.%03u", hours, minutes, seconds, (unsigned)(dsecs / 1000)); - else if (minutes > 0) sprintf(r, "%02u:%02u.%03u", minutes, seconds, (unsigned)(dsecs / 1000)); - else sprintf(r, "%02u.%03u", seconds, (unsigned)(dsecs / 1000)); + if (days > 0) sprintf(r, "%ud,%02u:%02u:%02u.%04u", days, hours, minutes, seconds, (unsigned)(dsecs / 100)); + else if (hours > 0) sprintf(r, "%02u:%02u:%02u.%04u", hours, minutes, seconds, (unsigned)(dsecs / 100)); + else if (minutes > 0) sprintf(r, "%02u:%02u.%04u", minutes, seconds, (unsigned)(dsecs / 100)); + else sprintf(r, "%02u.%04u", seconds, (unsigned)(dsecs / 100)); return r; }