* tfcrypt -- high security Threefish encryption tool.
*
* tfcrypt is copyrighted:
- * Copyright (C) 2012-2018 Andrey Rys. All rights reserved.
+ * Copyright (C) 2012-2019 Andrey Rys. All rights reserved.
*
* tfcrypt is licensed to you under the terms of std. MIT/X11 license:
*
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;
cur = lseek(fd, 0L, SEEK_CUR);
l = lseek(fd, 0L, SEEK_SET);
- if (l == -1) return -1;
+ if (l == -1) return NOFSIZE;
l = lseek(fd, 0L, SEEK_END);
- if (l == -1) return -1;
+ if (l == -1) return NOFSIZE;
lseek(fd, cur, SEEK_SET);
return (tfc_fsize)l;
}
+tfc_fsize tfc_fdgetpos(int fd)
+{
+ off_t t;
+
+ t = lseek(fd, 0L, SEEK_CUR);
+ if (t == (off_t)-1) return NOFSIZE;
+ return (tfc_fsize)t;
+}
+
tfc_fsize tfc_fnamesize(char *fname, tfc_yesno noexit)
{
int fnmfd;