move atexit code to xexit() and fix ftrunc order for mtime.
[tfcrypt.git] / tfc_error.c
index 16e4cd0352010ced823d281de6fb6e3d7ac987f5..3d95eba0cae6387a14800c4dfa7705ee52c1e447 100644 (file)
@@ -62,6 +62,14 @@ _ex:
 
 void xexit(int status)
 {
+       xclose(sfd);
+       if (do_ftrunc > TFC_NO_FTRUNC) {
+               if (do_ftrunc == TFC_FTRUNC_TAIL) ftrunc_dfd = total_processed_dst;
+               if (ftruncate(dfd, (off_t)ftrunc_dfd) == -1) xerror(YES, NO, YES, "ftruncate(%d)", dfd);
+       }
+       if (do_preserve_time) fcopy_matime(dfd, &s_stat);
+       xclose(dfd);
+
        memset(srcblk, 0, sizeof(srcblk));
        memset(dstblk, 0, sizeof(dstblk));
 
@@ -91,11 +99,14 @@ void usage(void)
        tfc_yesno is_embedded_prog = NO;
 
        if (optopt == 'V') {
-               char shash[64];
                tfc_say("tfcrypt toolkit, version %s.", _TFCRYPT_VERSION);
-               hash_defaults(shash, sizeof(shash));
-               tfc_say("Defaults hash: %s", shash);
-               memset(shash, 0, sizeof(shash));
+               if (ctr_mode != TFC_MODE_PLAIN) {
+                       char shash[64];
+
+                       hash_defaults(shash, sizeof(shash));
+                       tfc_say("Defaults hash: %s", shash);
+                       memset(shash, 0, sizeof(shash));
+               }
                xexit(0);
        }
 
@@ -266,7 +277,11 @@ void usage(void)
        tfc_say("    -: read a detached MAC signature from stdin,");
        tfc_say("    drop: do not verify attached MAC, if any, and drop it from output.");
        tfc_say("  -m: just verify MAC provided with -M. Do not write output file.");
-       tfc_say("    This option must be specified after -M.");
+       tfc_say("  -u: almost same as -m, but turns on MAC pre-test mode, when verified");
+       tfc_say("    signature enables writing output file. It is useful when decrypting small texts.");
+       tfc_say("    The source must be a seekable file, otherwise this mode will be disabled.");
+       tfc_say("    In this mode, decryption is done twice and verification done once.");
+       tfc_say("    Both -m and -u options must be specified after -M.");
        tfc_say("  -E how: how to behave on I/O errors (both src or dst):");
        tfc_say("    exit: print error if not quiet, then exit,");
        tfc_say("    cont: print error if not quiet, then continue,");