line is found, @command{md5sum} exits with nonzero status. Otherwise,
it exits successfully.
+@itemx --quiet
+@opindex --quiet
+@cindex verifying MD5 checksums
+This option is useful only when verifying checksums.
+When verifying checksums, don't generate an 'OK' message per successfully
+checked file. Files that fail the verification are reported in the
+default one-line-per-file format. If there is any checksum mismatch,
+print a warning summarizing the failures to standard error.
+
@itemx --status
@opindex --status
@cindex verifying MD5 checksums
improperly formatted checksum line. */
static bool warn = false;
+/* With --check, suppress the "OK" printed for each verified file. */
+static bool quiet = false;
+
/* The name this program was run with. */
char *program_name;
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
- STATUS_OPTION = CHAR_MAX + 1
+ STATUS_OPTION = CHAR_MAX + 1,
+ QUIET_OPTION
};
static const struct option long_options[] =
{
{ "binary", no_argument, NULL, 'b' },
{ "check", no_argument, NULL, 'c' },
+ { "quiet", no_argument, NULL, QUIET_OPTION },
{ "status", no_argument, NULL, STATUS_OPTION },
{ "text", no_argument, NULL, 't' },
{ "warn", no_argument, NULL, 'w' },
"), stdout);
fputs (_("\
\n\
-The following two options are useful only when verifying checksums:\n\
+The following three options are useful only when verifying checksums:\n\
+ --quiet don't print OK for each successfully verified file\n\
--status don't output anything, status code shows success\n\
-w, --warn warn about improperly formatted checksum lines\n\
\n\
if (!status_only)
{
- printf ("%s: %s\n", filename,
- (cnt != digest_bin_bytes ? _("FAILED") : _("OK")));
+ if (cnt != digest_bin_bytes)
+ printf ("%s: %s\n", filename, _("FAILED"));
+ else if (!quiet)
+ printf ("%s: %s\n", filename, _("OK"));
fflush (stdout);
}
}
case STATUS_OPTION:
status_only = true;
warn = false;
+ quiet = false;
break;
case 't':
binary = 0;
case 'w':
status_only = false;
warn = true;
+ quiet = false;
+ break;
+ case QUIET_OPTION:
+ status_only = false;
+ warn = false;
+ quiet = true;
break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
usage (EXIT_FAILURE);
}
+ if (quiet & !do_check)
+ {
+ error (0, 0,
+ _("the --quiet option is meaningful only when verifying checksums"));
+ usage (EXIT_FAILURE);
+ }
+
if (!O_BINARY && binary < 0)
binary = 0;
{OUT=>"f: OK\n"}],
['check-2', '--check', '--status', {IN=>{'f.md5' => "$degenerate f\n"}},
{AUX=> {f=> 'foo'}}, {EXIT=> 1}],
+ ['check-quiet1', '--check', '--quiet', {AUX=> {f=> ''}},
+ {IN=> {'f.md5' => "$degenerate f\n"}},
+ {OUT=>""}],
+ ['check-quiet2', '--check', '--quiet',
+ {IN=>{'f.md5' => "$degenerate f\n"}},
+ {AUX=> {f=> 'foo'}}, {OUT=>"f: FAILED\n"},
+ {ERR=>"md5sum: WARNING: 1 of 1 computed"
+ . " checksum did NOT match\n"},
+ {EXIT=> 1}],
# The sha1sum and md5sum drivers share a lot of code.
# Ensure that md5sum does *not* share the part that makes
# sha1sum accept BSD format.