/* chmod -- change permission modes of files
- Copyright (C) 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "modechange.h"
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "savedir.h"
CH_NO_CHANGE_REQUESTED
};
+enum Verbosity
+{
+ /* Print a message for each file that is processed. */
+ V_high,
+
+ /* Print a message for each file whose attributes we change. */
+ V_changes_only,
+
+ /* Do not be verbose. This is the default. */
+ V_off
+};
+
void mode_string ();
void strip_trailing_slashes ();
/* If nonzero, force silence (no error messages). */
static int force_silent;
-/* If nonzero, describe the modes we set. */
-static int verbose;
+/* Level of verbosity. */
+static enum Verbosity verbosity = V_off;
/* The argument to the --reference option. Use the owner and group IDs
of this file. This file must exist. */
static char *reference_file;
-/* If nonzero, describe only modes that change. */
-static int changes_only;
-
/* If nonzero, display usage information and exit. */
static int show_help;
{
int fail = chmod (file, (int) newmode);
- if (verbose || (changes_only && !fail))
+ if (verbosity == V_high || (verbosity == V_changes_only && !fail))
describe_change (file, newmode, (fail ? CH_FAILED : CH_SUCCEEDED));
if (fail)
errors = 1;
}
}
- else if (verbose && changes_only == 0)
+ else if (verbosity == V_high)
describe_change (file, newmode, CH_NO_CHANGE_REQUESTED);
if (recurse && S_ISDIR (file_stats.st_mode))
one or more of the letters rwxXstugo.\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
- recurse = force_silent = verbose = changes_only = 0;
+ recurse = force_silent = 0;
while (1)
{
recurse = 1;
break;
case 'c':
- changes_only = 1;
+ verbosity = V_changes_only;
break;
case 'f':
force_silent = 1;
break;
case 'v':
- verbose = 1;
+ verbosity = V_high;
break;
default:
usage (1);
if (show_version)
{
printf ("chmod (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
errors |= change_file_mode (argv[optind], changes, 1);
}
+ if (verbosity != V_off)
+ close_stdout ();
exit (errors);
}
/* chown -- change user and group ownership of files
- Copyright (C) 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <getopt.h>
#include "system.h"
+#include "closeout.h"
#include "error.h"
#include "savedir.h"
CH_NO_CHANGE_REQUESTED
};
+enum Verbosity
+{
+ /* Print a message for each file that is processed. */
+ V_high,
+
+ /* Print a message for each file whose attributes we change. */
+ V_changes_only,
+
+ /* Do not be verbose. This is the default. */
+ V_off
+};
+
static int change_dir_owner PARAMS ((const char *dir, uid_t user, gid_t group,
struct stat *statp));
/* If nonzero, force silence (no error messages). */
static int force_silent;
-/* If nonzero, describe the files we process. */
-static int verbose;
-
-/* If nonzero, describe only owners or groups that change. */
-static int changes_only;
+/* Level of verbosity. */
+static enum Verbosity verbosity = V_off;
/* The name of the user to which ownership of the files is being given. */
static char *username;
else
fail = chown (file, newuser, newgroup);
- if (verbose || (changes_only && !fail))
+ if (verbosity == V_high || (verbosity == V_changes_only && !fail))
describe_change (file, (fail ? CH_FAILED : CH_SUCCEEDED));
if (fail)
errors = 1;
}
}
- else if (verbose && changes_only == 0)
+ else if (verbosity == V_high)
{
describe_change (file, CH_NO_CHANGE_REQUESTED);
}
to login group if implied by a period. A colon may replace the period.\n\
"));
puts (_("\nReport bugs to <fileutils-bugs@gnu.org>."));
+ close_stdout ();
}
exit (status);
}
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
- recurse = force_silent = verbose = changes_only = 0;
+ recurse = force_silent = 0;
while ((optc = getopt_long (argc, argv, "Rcfhv", long_options, NULL)) != -1)
{
recurse = 1;
break;
case 'c':
- verbose = 1;
- changes_only = 1;
+ verbosity = V_changes_only;
break;
case 'f':
force_silent = 1;
change_symlinks = 1;
break;
case 'v':
- verbose = 1;
+ verbosity = V_high;
break;
default:
usage (1);
if (show_version)
{
printf ("chown (%s) %s\n", GNU_PACKAGE, VERSION);
+ close_stdout ();
exit (0);
}
errors |= change_file_owner (argv[optind], user, group);
}
+ if (verbosity != V_off)
+ close_stdout ();
exit (errors);
}