X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_misc.c;h=2aa58df4b5fd46ea9d579f3be3e4cafb85067e0f;hb=370a18a4c47e236b51ad8dee1957c40e11346b96;hp=44e1117be6342ec710d8e6848824cd55b9d6f895;hpb=cdd9119e29f2f865403303adb8b6004b863db968;p=tfcrypt.git diff --git a/tfc_misc.c b/tfc_misc.c index 44e1117..2aa58df 100644 --- a/tfc_misc.c +++ b/tfc_misc.c @@ -63,6 +63,26 @@ tfc_yesno str_empty(const char *str) 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; @@ -77,12 +97,23 @@ const char *tfc_modename(int mode) 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 timespec t; @@ -164,7 +195,7 @@ tfc_fsize tfc_fnamesize(char *fname, tfc_yesno noexit) 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);