X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_misc.c;h=44e1117be6342ec710d8e6848824cd55b9d6f895;hb=2a9a13e951cb7bcc4d81b3e6f1e23c5185ec77af;hp=06c1a653e7d6a3ac23047288f6e7224e15b83789;hpb=0303cbcec2b262cc3dcf8d89951967d7ba9543c7;p=tfcrypt.git diff --git a/tfc_misc.c b/tfc_misc.c index 06c1a65..44e1117 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 = 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,21 @@ 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; +} + +char *tfc_format_pid(const char *str) +{ + static char r[128]; + size_t n; + + n = xstrlcpy(r, str, sizeof(r)); + if (show_pid == YES && sizeof(r)-n >= 22) sprintf(r+n, "[%lu]", (unsigned long)progpid); return r; } @@ -135,7 +146,7 @@ tfc_fsize tfc_fdgetpos(int fd) off_t t; t = lseek(fd, 0L, SEEK_CUR); - if (t == -1) return NOFSIZE; + if (t == (off_t)-1) return NOFSIZE; return (tfc_fsize)t; }