return NO;
}
+int xxopen(tfc_yesno noerr, const char *pathname, int flags)
+{
+ int r;
+
+ if ((flags & O_WRONLY || flags & O_RDWR)) {
+ if (read_only == YES) flags = O_RDONLY;
+ else flags |= write_flags;
+ }
+
+ flags |= O_LARGEFILE;
+ r = open(pathname, flags, 0666);
+ if (noerr == NO && r == -1) xerror(NO, NO, YES, "%s", pathname);
+ return r;
+}
+
+int xopen(const char *pathname, int flags)
+{
+ return xxopen(NO, pathname, flags);
+}
+
void xclose(int fd)
{
if (fd < 3) return;
case TFC_MODE_XTS: return "XTS";
case TFC_MODE_ECB: return "ECB";
case TFC_MODE_CBC: return "CBC";
- case TFC_MODE_OCB: return "OCB";
+ case TFC_MODE_PCBC: return "PCBC";
}
return NULL;
}
+tfc_yesno tfc_is_freestream(int mode)
+{
+ switch (mode) {
+ case TFC_MODE_PLAIN:
+ case TFC_MODE_XOR:
+ case TFC_MODE_STREAM: return YES;
+ }
+
+ return NO;
+}
+
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));
}
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;
}
memset(s, 0, 2);
}
- fnmfd = open(fname, O_RDONLY);
+ fnmfd = xxopen(YES, fname, O_RDONLY);
if (s) memcpy(s, T, 2);
if (fnmfd == -1) {
xerror(noexit, NO, YES, "%s", fname);