X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_misc.c;h=3bfd214c1914163bf0019a4241e52eb11a035a8c;hb=cd6f1f9a84c17dbdf6ab320a04eae300502b898d;hp=f55726ac897974471b33f9ad4422bc4463ddccfe;hpb=f761a53231d1a023e2d3e5efcc5591b04a34f98a;p=tfcrypt.git diff --git a/tfc_misc.c b/tfc_misc.c index f55726a..3bfd214 100644 --- a/tfc_misc.c +++ b/tfc_misc.c @@ -89,11 +89,33 @@ void tfc_getcurtime(tfc_useconds *tx) memset(&t, 0, sizeof(t)); gettimeofday(&t, NULL); - *tx = t.tv_sec * 1000000 + t.tv_usec; + *tx = (tfc_useconds)t.tv_sec * 1000000 + t.tv_usec; memset(&t, 0, sizeof(t)); } +char *tfc_format_time(tfc_useconds t) +{ + tfc_useconds secs, dsecs; + unsigned days, hours, minutes, seconds; + static char r[128]; + + secs = (tfc_useconds)TFC_UTODSECS(t); + dsecs = (tfc_useconds)(t - (secs * 1000000)); + + days = secs / 86400; + hours = (secs / 3600) % 24; + 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)); + + return r; +} + tfc_fsize tfc_fdsize(int fd) { off_t l, cur; @@ -113,7 +135,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; }