[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coreutils chmod int->bool cleanup
From: |
Paul Eggert |
Subject: |
coreutils chmod int->bool cleanup |
Date: |
Thu, 29 Jul 2004 21:09:06 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
I installed the following minor int->bool cleanups for coreutils chmod.
This doesn't fix any bugs.
2004-07-29 Paul Eggert <address@hidden>
* lib/modechange.c: Include <stdbool.h>.
(mode_compile): Use bool when appropriate.
* src/chmod.c (recurse, force_silent, process_file, process_files,
main): Use bool when appropriate.
Index: lib/modechange.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/modechange.c,v
retrieving revision 1.25
diff -p -u -r1.25 modechange.c
--- lib/modechange.c 10 Sep 2003 09:05:31 -0000 1.25
+++ lib/modechange.c 14 Jul 2004 23:18:21 -0000
@@ -33,6 +33,7 @@
#include "modechange.h"
#include <sys/stat.h>
#include "xstrtol.h"
+#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
@@ -220,12 +221,10 @@ mode_compile (const char *mode_string, u
/* `affected_bits' modified by umask. */
mode_t affected_masked;
/* Operators to actually use umask on. */
- unsigned ops_to_mask = 0;
+ unsigned int ops_to_mask = 0;
- int who_specified_p;
+ bool who_specified_p;
- affected_bits = 0;
- ops_to_mask = 0;
/* Turn on all the bits in `affected_bits' for each group given. */
for (++mode_string;; ++mode_string)
switch (*mode_string)
@@ -250,10 +249,10 @@ mode_compile (const char *mode_string, u
/* If none specified, affect all bits, except perhaps those
set in the umask. */
if (affected_bits)
- who_specified_p = 1;
+ who_specified_p = true;
else
{
- who_specified_p = 0;
+ who_specified_p = false;
affected_bits = CHMOD_MODE_BITS;
ops_to_mask = masked_ops;
}
Index: src/chmod.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/chmod.c,v
retrieving revision 1.104
diff -p -u -r1.104 chmod.c
--- src/chmod.c 21 Jun 2004 15:03:35 -0000 1.104
+++ src/chmod.c 20 Jul 2004 04:38:20 -0000
@@ -60,11 +60,11 @@ enum Verbosity
/* The name the program was run with. */
char *program_name;
-/* If nonzero, change the modes of directories recursively. */
-static int recurse;
+/* If true, change the modes of directories recursively. */
+static bool recurse;
-/* If nonzero, force silence (no error messages). */
-static int force_silent;
+/* If true, force silence (no error messages). */
+static bool force_silent;
/* Level of verbosity. */
static enum Verbosity verbosity = V_off;
@@ -161,55 +161,55 @@ describe_change (const char *file, mode_
abort ();
}
printf (fmt, quote (file),
- (unsigned long) (mode & CHMOD_MODE_BITS), &perms[1]);
+ (unsigned long int) (mode & CHMOD_MODE_BITS), &perms[1]);
}
/* Change the mode of FILE according to the list of operations CHANGES.
- Return 0 if successful, -1 if errors occurred. This function is called
+ Return true if successful. This function is called
once for every file system object that fts encounters. */
-static int
+static bool
process_file (FTS *fts, FTSENT *ent, const struct mode_change *changes)
{
char const *file_full_name = ent->fts_path;
char const *file = ent->fts_accpath;
const struct stat *file_stats = ent->fts_statp;
mode_t new_mode IF_LINT (= 0);
- int errors = 0;
+ bool ok = true;
bool do_chmod;
bool symlink_changed = true;
switch (ent->fts_info)
{
case FTS_DP:
- return 0;
+ return true;
case FTS_NS:
error (0, ent->fts_errno, _("cannot access %s"), quote (file_full_name));
- errors = -1;
+ ok = false;
break;
case FTS_ERR:
error (0, ent->fts_errno, _("%s"), quote (file_full_name));
- errors = -1;
+ ok = false;
break;
case FTS_DNR:
error (0, ent->fts_errno, _("cannot read directory %s"),
quote (file_full_name));
- errors = -1;
+ ok = false;
break;
default:
break;
}
- do_chmod = !errors;
+ do_chmod = ok;
if (do_chmod && ROOT_DEV_INO_CHECK (root_dev_ino, file_stats))
{
ROOT_DEV_INO_WARN (file_full_name);
- errors = -1;
+ ok = false;
do_chmod = false;
}
@@ -221,9 +221,9 @@ process_file (FTS *fts, FTSENT *ent, con
symlink_changed = false;
else
{
- errors = chmod (file, new_mode);
+ ok = (chmod (file, new_mode) == 0);
- if (errors && !force_silent)
+ if (! (ok | force_silent))
error (0, errno, _("changing permissions of %s"),
quote (file_full_name));
}
@@ -232,13 +232,13 @@ process_file (FTS *fts, FTSENT *ent, con
if (verbosity != V_off)
{
bool changed =
- (!errors && symlink_changed
+ (ok && symlink_changed
&& mode_changed (file, file_stats->st_mode, new_mode));
if (changed || verbosity == V_high)
{
enum Change_status ch_status =
- (errors ? CH_FAILED
+ (!ok ? CH_FAILED
: !symlink_changed ? CH_NOT_APPLIED
: !changed ? CH_NO_CHANGE_REQUESTED
: CH_SUCCEEDED);
@@ -249,19 +249,18 @@ process_file (FTS *fts, FTSENT *ent, con
if ( ! recurse)
fts_set (fts, ent, FTS_SKIP);
- return errors;
+ return ok;
}
/* Recursively change the modes of the specified FILES (the last entry
of which is NULL) according to the list of operations CHANGES.
BIT_FLAGS controls how fts works.
- If the fts_open call fails, exit nonzero.
- Otherwise, return nonzero upon error. */
+ Return true if successful. */
-static int
+static bool
process_files (char **files, int bit_flags, const struct mode_change *changes)
{
- int fail = 0;
+ bool ok = true;
FTS *fts = xfts_open (files, bit_flags, NULL);
@@ -276,12 +275,12 @@ process_files (char **files, int bit_fla
{
/* FIXME: try to give a better message */
error (0, errno, _("fts_read failed"));
- fail = 1;
+ ok = false;
}
break;
}
- fail |= process_file (fts, ent, changes);
+ ok &= process_file (fts, ent, changes);
}
/* Ignore failure, since the only way it can do so is in failing to
@@ -289,7 +288,7 @@ process_files (char **files, int bit_fla
that doesn't matter. */
fts_close (fts);
- return fail;
+ return ok;
}
void
@@ -340,7 +339,7 @@ int
main (int argc, char **argv)
{
struct mode_change *changes;
- int fail = 0;
+ bool ok;
int modeind = 0; /* Index of the mode argument in `argv'. */
int thisind;
bool preserve_root = false;
@@ -354,7 +353,7 @@ main (int argc, char **argv)
atexit (close_stdout);
- recurse = force_silent = 0;
+ recurse = force_silent = false;
while (1)
{
@@ -402,13 +401,13 @@ main (int argc, char **argv)
reference_file = optarg;
break;
case 'R':
- recurse = 1;
+ recurse = true;
break;
case 'c':
verbosity = V_changes_only;
break;
case 'f':
- force_silent = 1;
+ force_silent = true;
break;
case 'v':
verbosity = V_high;
@@ -444,7 +443,7 @@ main (int argc, char **argv)
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quote (reference_file));
- if (recurse && preserve_root)
+ if (recurse & preserve_root)
{
static struct dev_ino dev_ino_buf;
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
@@ -457,7 +456,7 @@ main (int argc, char **argv)
root_dev_ino = NULL;
}
- fail = process_files (argv + optind, FTS_COMFOLLOW, changes);
+ ok = process_files (argv + optind, FTS_COMFOLLOW, changes);
- exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- coreutils chmod int->bool cleanup,
Paul Eggert <=