bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

int->bool etc. cleanup for coreutils cp, mv, install, rm


From: Paul Eggert
Subject: int->bool etc. cleanup for coreutils cp, mv, install, rm
Date: Fri, 30 Jul 2004 01:12:13 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

I installed this patch to use bool (and size_t) when possible, instead
of int.  I don't think it fixes any bugs.

2004-07-29  Paul Eggert  <address@hidden>

        * src/copy.h (struct cp_options): Likewise.
        * src/copy.c (copy_internal, is_ancestor, copy_dir, copy_reg,
        same_file_ok, seen_file, copy_internal, valid_options, copy): Likewise.
        * src/cp-hash.h (remember_created): Likewise.
        * src/cp-hash.c (remember_created): Likewise.
        * src/cp.c (struct dir_attr, flag_path, remove_trailing_slashes,
        re_protect, make_path_private, target_directory_operand, do_copy,
        cp_option_init, decode_preserve_arg, main): Likewise.
        * src/install.c (isdir, change_timestamps, change_attributes,
        copy_file, install_file_to_path, install_file_in_dir,
        install_file_in_file, strip_files, dir_arg, cp_option_init, main,
        change_attributes, change_timestamps): Likewise.
        * src/mv.c (remove_trailing_slashes, rm_option_init,
        cp_option_init, do_move, movefile, main): Likewise.
        * src/remove.c (right_justify), full_filename_, AD_pop_and_chdir,
        AD_push, prompt, remove_dir): Likewise.
        * src/rm.c (rm_option_init, main): Likewise.

        * src/remove.c (top_dir, pop_dir, full_filename_):
        Use size_t for sizes.
        * src/cp.c (target_directory_operand): Do not clear *NEW_DST if stat
        succeeds.  It's not necessary in that case, as *NEW_DST is always
        false already.
        (do_copy): Rewrite slightly to avoid need for "unreachable" comment.
        (main): Use EXIT_SUCCESS, EXIT_FAILURE instead of 0, 1.
        * src/rm.c (main): Likewise.

Index: copy.h
===================================================================
RCS file: /home/eggert/coreutils/cu/src/copy.h,v
retrieving revision 1.29
diff -p -u -r1.29 copy.h
--- copy.h      30 Jun 2004 22:33:40 -0000      1.29
+++ copy.h      15 Jul 2004 18:09:32 -0000
@@ -1,6 +1,7 @@
 #ifndef COPY_H
 # define COPY_H
 
+# include <stdbool.h>
 # include "hash.h"
 
 /* Control creation of sparse files (files with holes).  */
@@ -62,52 +63,52 @@ struct cp_options
 {
   enum backup_type backup_type;
 
-  /* If nonzero, copy all files except (directories and, if not dereferencing
-     them, symbolic links,) as if they were regular files. */
-  int copy_as_regular;
+  /* If true, copy all files except (directories and, if not dereferencing
+     them, symbolic links,) as if they were regular files.  */
+  bool copy_as_regular;
 
   /* How to handle symlinks.  */
   enum Dereference_symlink dereference;
 
-  /* If nonzero, remove each existing destination nondirectory before
-     trying to open it. */
-  int unlink_dest_before_opening;
+  /* If true, remove each existing destination nondirectory before
+     trying to open it.  */
+  bool unlink_dest_before_opening;
 
-  /* If nonzero, first try to open each existing destination nondirectory,
+  /* If true, first try to open each existing destination nondirectory,
      then, if the open fails, unlink and try again.
      This option must be set for `cp -f', in case the destination file
      exists when the open is attempted.  It is irrelevant to `mv' since
      any destination is sure to be removed before the open.  */
-  int unlink_dest_after_failed_open;
+  bool unlink_dest_after_failed_open;
 
-  /* If nonzero, create hard links instead of copying files.
+  /* If true, create hard links instead of copying files.
      Create destination directories as usual. */
-  int hard_link;
+  bool hard_link;
 
   /* This value is used to determine whether to prompt before removing
      each existing destination file.  It works differently depending on
      whether move_mode is set.  See code/comments in copy.c.  */
   enum Interactive interactive;
 
-  /* If nonzero, rather than copying, first attempt to use rename.
+  /* If true, rather than copying, first attempt to use rename.
      If that fails, then resort to copying.  */
-  int move_mode;
+  bool move_mode;
 
   /* This process's effective user ID.  */
   uid_t myeuid;
 
-  /* If nonzero, when copying recursively, skip any subdirectories that are
+  /* If true, when copying recursively, skip any subdirectories that are
      on different file systems from the one we started on.  */
-  int one_file_system;
+  bool one_file_system;
 
-  /* If nonzero, attempt to give the copies the original files' permissions,
+  /* If true, attempt to give the copies the original files' permissions,
      owner, group, and timestamps. */
-  int preserve_ownership;
-  int preserve_mode;
-  int preserve_timestamps;
+  bool preserve_ownership;
+  bool preserve_mode;
+  bool preserve_timestamps;
 
   /* Enabled for mv, and for cp by the --preserve=links option.
-     If nonzero, attempt to preserve in the destination files any
+     If true, attempt to preserve in the destination files any
      logical hard links between the source files.  If used with cp's
      --no-dereference option, and copying two hard-linked files,
      the two corresponding destination files will also be hard linked.
@@ -116,45 +117,45 @@ struct cp_options
      hard links are *not* preserved.  However, when copying a file F and
      a symlink S to F, the resulting S and F in the destination directory
      will be hard links to the same file (a copy of F).  */
-  int preserve_links;
+  bool preserve_links;
 
-  /* If nonzero and any of the above (for preserve) file attributes cannot
+  /* If true and any of the above (for preserve) file attributes cannot
      be applied to a destination file, treat it as a failure and return
      nonzero immediately.  E.g. cp -p requires this be nonzero, mv requires
      it be zero.  */
-  int require_preserve;
+  bool require_preserve;
 
-  /* If nonzero, copy directories recursively and copy special files
+  /* If true, copy directories recursively and copy special files
      as themselves rather than copying their contents. */
-  int recursive;
+  bool recursive;
 
-  /* If nonzero, set file mode to value of MODE.  Otherwise,
+  /* If true, set file mode to value of MODE.  Otherwise,
      set it based on current umask modified by UMASK_KILL.  */
-  int set_mode;
+  bool set_mode;
 
   /* Set the mode of the destination file to exactly this value
-     if USE_MODE is nonzero.  */
+     if SET_MODE is nonzero.  */
   mode_t mode;
 
   /* Control creation of sparse files.  */
   enum Sparse_type sparse_mode;
 
-  /* If nonzero, create symbolic links instead of copying files.
+  /* If true, create symbolic links instead of copying files.
      Create destination directories as usual. */
-  int symbolic_link;
+  bool symbolic_link;
 
   /* The bits to preserve in created files' modes. */
   mode_t umask_kill;
 
-  /* If nonzero, do not copy a nondirectory that has an existing destination
+  /* If true, do not copy a nondirectory that has an existing destination
      with the same or newer modification time. */
-  int update;
+  bool update;
 
-  /* If nonzero, display the names of the files before copying them. */
-  int verbose;
+  /* If true, display the names of the files before copying them. */
+  bool verbose;
 
-  /* If nonzero, stdin is a tty.  */
-  int stdin_tty;
+  /* If true, stdin is a tty.  */
+  bool stdin_tty;
 
   /* This is a set of destination name/inode/dev triples.  Each such triple
      represents a file we have created corresponding to a source file name
@@ -199,10 +200,10 @@ int rpl_rename (const char *, const char
 #  define rename rpl_rename
 # endif
 
-int
+bool
 copy (const char *src_path, const char *dst_path,
-      int nonexistent_dst, const struct cp_options *options,
-      int *copy_into_self, int *rename_succeeded);
+      bool nonexistent_dst, const struct cp_options *options,
+      bool *copy_into_self, bool *rename_succeeded);
 
 void
 dest_info_init (struct cp_options *);
Index: copy.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/copy.c,v
retrieving revision 1.169
diff -p -u -r1.169 copy.c
--- copy.c      27 Jul 2004 23:13:38 -0000      1.169
+++ copy.c      27 Jul 2004 23:42:51 -0000
@@ -80,13 +80,13 @@ struct F_triple
 /* Initial size of the above hash table.  */
 #define DEST_INFO_INITIAL_CAPACITY 61
 
-static int copy_internal (const char *src_path, const char *dst_path,
-                         int new_dst, dev_t device,
-                         struct dir_list *ancestors,
-                         const struct cp_options *x,
-                         int command_line_arg,
-                         int *copy_into_self,
-                         int *rename_succeeded);
+static bool copy_internal (const char *src_path, const char *dst_path,
+                          bool new_dst, dev_t device,
+                          struct dir_list *ancestors,
+                          const struct cp_options *x,
+                          bool command_line_arg,
+                          bool *copy_into_self,
+                          bool *rename_succeeded);
 
 /* Pointers to the file names:  they're used in the diagnostic that is issued
    when we detect the user is trying to copy a directory into itself.  */
@@ -121,35 +121,35 @@ get_dest_mode (const struct cp_options *
    performance hit that's probably noticeable only on trees deeper
    than a few hundred levels.  See use of active_dir_map in remove.c  */
 
-static int
+static bool
 is_ancestor (const struct stat *sb, const struct dir_list *ancestors)
 {
   while (ancestors != 0)
     {
       if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev)
-       return 1;
+       return true;
       ancestors = ancestors->parent;
     }
-  return 0;
+  return false;
 }
 
 /* Read the contents of the directory SRC_PATH_IN, and recursively
-   copy the contents to DST_PATH_IN.  NEW_DST is nonzero if
+   copy the contents to DST_PATH_IN.  NEW_DST is true if
    DST_PATH_IN is a directory that was created previously in the
    recursion.   SRC_SB and ANCESTORS describe SRC_PATH_IN.
-   Set *COPY_INTO_SELF to nonzero if SRC_PATH_IN is a parent of
-   (or the same as) DST_PATH_IN;  otherwise, set it to zero.
-   Return 0 if successful, -1 if an error occurs. */
+   Set *COPY_INTO_SELF if SRC_PATH_IN is a parent of
+   (or the same as) DST_PATH_IN; otherwise, clear it.
+   Return true if successful.  */
 
-static int
-copy_dir (const char *src_path_in, const char *dst_path_in, int new_dst,
+static bool
+copy_dir (const char *src_path_in, const char *dst_path_in, bool new_dst,
          const struct stat *src_sb, struct dir_list *ancestors,
-         const struct cp_options *x, int *copy_into_self)
+         const struct cp_options *x, bool *copy_into_self)
 {
   char *name_space;
   char *namep;
   struct cp_options non_command_line_options = *x;
-  int ret = 0;
+  bool ok = true;
 
   name_space = savedir (src_path_in);
   if (name_space == NULL)
@@ -157,7 +157,7 @@ copy_dir (const char *src_path_in, const
       /* This diagnostic is a bit vague because savedir can fail in
          several different ways.  */
       error (0, errno, _("cannot access %s"), quote (src_path_in));
-      return -1;
+      return false;
     }
 
   /* For cp's -H option, dereference command line arguments, but do not
@@ -168,13 +168,13 @@ copy_dir (const char *src_path_in, const
   namep = name_space;
   while (*namep != '\0')
     {
-      int local_copy_into_self;
+      bool local_copy_into_self;
       char *src_path = path_concat (src_path_in, namep, NULL);
       char *dst_path = path_concat (dst_path_in, namep, NULL);
 
-      ret |= copy_internal (src_path, dst_path, new_dst, src_sb->st_dev,
-                           ancestors, &non_command_line_options, 0,
-                           &local_copy_into_self, NULL);
+      ok &= copy_internal (src_path, dst_path, new_dst, src_sb->st_dev,
+                          ancestors, &non_command_line_options, false,
+                          &local_copy_into_self, NULL);
       *copy_into_self |= local_copy_into_self;
 
       free (dst_path);
@@ -183,7 +183,7 @@ copy_dir (const char *src_path_in, const
       namep += strlen (namep) + 1;
     }
   free (name_space);
-  return -ret;
+  return ok;
 }
 
 /* Copy a regular file from SRC_PATH to DST_PATH.
@@ -192,13 +192,13 @@ copy_dir (const char *src_path_in, const
    (Holes are read as zeroes by the `read' system call.)
    Use DST_MODE as the 3rd argument in the call to open.
    X provides many option settings.
-   Return 0 if successful, -1 if an error occurred.
+   Return true if successful.
    *NEW_DST is as in copy_internal.  SRC_SB is the result
    of calling xstat (aka stat in this case) on SRC_PATH.  */
 
-static int
+static bool
 copy_reg (const char *src_path, const char *dst_path,
-         const struct cp_options *x, mode_t dst_mode, int *new_dst,
+         const struct cp_options *x, mode_t dst_mode, bool *new_dst,
          struct stat const *src_sb)
 {
   char *buf;
@@ -210,22 +210,22 @@ copy_reg (const char *src_path, const ch
   struct stat src_open_sb;
   char *cp;
   int *ip;
-  int return_val = 0;
+  bool return_val = true;
   off_t n_read_total = 0;
-  int last_write_made_hole = 0;
-  int make_holes = 0;
+  bool last_write_made_hole = false;
+  bool make_holes = false;
 
   source_desc = open (src_path, O_RDONLY);
   if (source_desc < 0)
     {
       error (0, errno, _("cannot open %s for reading"), quote (src_path));
-      return -1;
+      return false;
     }
 
   if (fstat (source_desc, &src_open_sb))
     {
       error (0, errno, _("cannot fstat %s"), quote (src_path));
-      return_val = -1;
+      return_val = false;
       goto close_src_desc;
     }
 
@@ -236,7 +236,7 @@ copy_reg (const char *src_path, const ch
       error (0, 0,
             _("skipping file %s, as it was replaced while being copied"),
             quote (src_path));
-      return_val = -1;
+      return_val = false;
       goto close_src_desc;
     }
 
@@ -255,12 +255,12 @@ copy_reg (const char *src_path, const ch
          if (unlink (dst_path))
            {
              error (0, errno, _("cannot remove %s"), quote (dst_path));
-             return_val = -1;
+             return_val = false;
              goto close_src_desc;
            }
 
          /* Tell caller that the destination file was unlinked.  */
-         *new_dst = 1;
+         *new_dst = true;
 
          /* Try the open again, but this time with different flags.  */
          dest_desc = open (dst_path, O_WRONLY | O_CREAT, dst_mode);
@@ -270,7 +270,7 @@ copy_reg (const char *src_path, const ch
   if (dest_desc < 0)
     {
       error (0, errno, _("cannot create regular file %s"), quote (dst_path));
-      return_val = -1;
+      return_val = false;
       goto close_src_desc;
     }
 
@@ -279,7 +279,7 @@ copy_reg (const char *src_path, const ch
   if (fstat (dest_desc, &sb))
     {
       error (0, errno, _("cannot fstat %s"), quote (dst_path));
-      return_val = -1;
+      return_val = false;
       goto close_src_and_dst_desc;
     }
 
@@ -288,7 +288,7 @@ copy_reg (const char *src_path, const ch
   /* Even with --sparse=always, try to create holes only
      if the destination is a regular file.  */
   if (x->sparse_mode == SPARSE_ALWAYS && S_ISREG (sb.st_mode))
-    make_holes = 1;
+    make_holes = true;
 
 #if HAVE_STRUCT_STAT_ST_BLOCKS
   if (x->sparse_mode == SPARSE_AUTO && S_ISREG (sb.st_mode))
@@ -299,7 +299,7 @@ copy_reg (const char *src_path, const ch
       if (fstat (source_desc, &sb))
        {
          error (0, errno, _("cannot fstat %s"), quote (src_path));
-         return_val = -1;
+         return_val = false;
          goto close_src_and_dst_desc;
        }
 
@@ -308,7 +308,7 @@ copy_reg (const char *src_path, const ch
         at least one of the blocks in the file is a hole. */
       if (S_ISREG (sb.st_mode)
          && sb.st_size / ST_NBLOCKSIZE > ST_NBLOCKS (sb))
-       make_holes = 1;
+       make_holes = true;
     }
 #endif
 
@@ -328,7 +328,7 @@ copy_reg (const char *src_path, const ch
            continue;
 #endif
          error (0, errno, _("reading %s"), quote (src_path));
-         return_val = -1;
+         return_val = false;
          goto close_src_and_dst_desc;
        }
       if (n_read == 0)
@@ -362,10 +362,10 @@ copy_reg (const char *src_path, const ch
              if (lseek (dest_desc, (off_t) n_read, SEEK_CUR) < 0L)
                {
                  error (0, errno, _("cannot lseek %s"), quote (dst_path));
-                 return_val = -1;
+                 return_val = false;
                  goto close_src_and_dst_desc;
                }
-             last_write_made_hole = 1;
+             last_write_made_hole = true;
            }
          else
            /* Clear to indicate that a normal write is needed. */
@@ -377,10 +377,10 @@ copy_reg (const char *src_path, const ch
          if (full_write (dest_desc, buf, n) != n)
            {
              error (0, errno, _("writing %s"), quote (dst_path));
-             return_val = -1;
+             return_val = false;
              goto close_src_and_dst_desc;
            }
-         last_write_made_hole = 0;
+         last_write_made_hole = false;
        }
     }
 
@@ -401,7 +401,7 @@ copy_reg (const char *src_path, const ch
 #endif
        {
          error (0, errno, _("writing %s"), quote (dst_path));
-         return_val = -1;
+         return_val = false;
        }
     }
 
@@ -409,19 +409,19 @@ close_src_and_dst_desc:
   if (close (dest_desc) < 0)
     {
       error (0, errno, _("closing %s"), quote (dst_path));
-      return_val = -1;
+      return_val = false;
     }
 close_src_desc:
   if (close (source_desc) < 0)
     {
       error (0, errno, _("closing %s"), quote (src_path));
-      return_val = -1;
+      return_val = false;
     }
 
   return return_val;
 }
 
-/* Return nonzero if it's ok that the source and destination
+/* Return true if it's ok that the source and destination
    files are the `same' by some measure.  The goal is to avoid
    making the `copy' operation remove both copies of the file
    in that case, while still allowing the user to e.g., move or
@@ -438,21 +438,21 @@ close_src_desc:
    mistakenly requires that such a rename call do *nothing* and return
    successfully.  */
 
-static int
+static bool
 same_file_ok (const char *src_path, const struct stat *src_sb,
              const char *dst_path, const struct stat *dst_sb,
-             const struct cp_options *x, int *return_now, int *unlink_src)
+             const struct cp_options *x, bool *return_now, bool *unlink_src)
 {
   const struct stat *src_sb_link;
   const struct stat *dst_sb_link;
   struct stat tmp_dst_sb;
   struct stat tmp_src_sb;
 
-  int same_link;
-  int same = (SAME_INODE (*src_sb, *dst_sb));
+  bool same_link;
+  bool same = SAME_INODE (*src_sb, *dst_sb);
 
-  *return_now = 0;
-  *unlink_src = 0;
+  *return_now = false;
+  *unlink_src = false;
 
   /* FIXME: this should (at the very least) be moved into the following
      if-block.  More likely, it should be removed, because it inhibits
@@ -461,8 +461,8 @@ same_file_ok (const char *src_path, cons
      be updated.  */
   if (same && x->hard_link)
     {
-      *return_now = 1;
-      return 1;
+      *return_now = true;
+      return true;
     }
 
   if (x->dereference == DEREF_NEVER)
@@ -481,11 +481,11 @@ same_file_ok (const char *src_path, cons
   else
     {
       if (!same)
-       return 1;
+       return true;
 
       if (lstat (dst_path, &tmp_dst_sb)
          || lstat (src_path, &tmp_src_sb))
-       return 1;
+       return true;
 
       src_sb_link = &tmp_src_sb;
       dst_sb_link = &tmp_dst_sb;
@@ -499,7 +499,7 @@ same_file_ok (const char *src_path, cons
         we'd end up truncating the source file.  */
       if (S_ISLNK (src_sb_link->st_mode) && S_ISLNK (dst_sb_link->st_mode)
          && x->unlink_dest_before_opening)
-       return 1;
+       return true;
     }
 
   /* The backup code ensures there's a copy, so it's usually ok to
@@ -531,9 +531,9 @@ same_file_ok (const char *src_path, cons
               && x->dereference != DEREF_NEVER
               && S_ISLNK (src_sb_link->st_mode)
               && ! S_ISLNK (dst_sb_link->st_mode))
-           return 0;
+           return false;
 
-         return 1;
+         return true;
        }
 
       return ! same_name (src_path, dst_path);
@@ -550,10 +550,10 @@ same_file_ok (const char *src_path, cons
   if (x->hard_link
       || !S_ISLNK (src_sb_link->st_mode)
       || S_ISLNK (dst_sb_link->st_mode))
-    return 1;
+    return true;
 
   if (x->dereference != DEREF_NEVER)
-    return 1;
+    return true;
 #endif
 
   /* They may refer to the same file if we're in move mode and the
@@ -564,7 +564,7 @@ same_file_ok (const char *src_path, cons
   if (x->move_mode || x->unlink_dest_before_opening)
     {
       if (S_ISLNK (dst_sb_link->st_mode))
-       return 1;
+       return true;
 
       if (same_link
          && 1 < dst_sb_link->st_nlink
@@ -572,10 +572,10 @@ same_file_ok (const char *src_path, cons
        {
          if (x->move_mode)
            {
-             *unlink_src = 1;
-             *return_now = 1;
+             *unlink_src = true;
+             *return_now = true;
            }
-         return 1;
+         return true;
        }
     }
 
@@ -584,13 +584,13 @@ same_file_ok (const char *src_path, cons
   if (!S_ISLNK (src_sb_link->st_mode) && !S_ISLNK (dst_sb_link->st_mode))
     {
       if (!SAME_INODE (*src_sb_link, *dst_sb_link))
-       return 1;
+       return true;
 
       /* If they are the same file, it's ok if we're making hard links.  */
       if (x->hard_link)
        {
-         *return_now = 1;
-         return 1;
+         *return_now = true;
+         return true;
        }
     }
 
@@ -606,25 +606,25 @@ same_file_ok (const char *src_path, cons
       if ( ! S_ISLNK (src_sb_link->st_mode))
        tmp_src_sb = *src_sb_link;
       else if (stat (src_path, &tmp_src_sb))
-       return 1;
+       return true;
 
       if ( ! S_ISLNK (dst_sb_link->st_mode))
        tmp_dst_sb = *dst_sb_link;
       else if (stat (dst_path, &tmp_dst_sb))
-       return 1;
+       return true;
 
       if ( ! SAME_INODE (tmp_src_sb, tmp_dst_sb))
-       return 1;
+       return true;
 
       /* FIXME: shouldn't this be testing whether we're making symlinks?  */
       if (x->hard_link)
        {
-         *return_now = 1;
-         return 1;
+         *return_now = true;
+         return true;
        }
     }
 
-  return 0;
+  return false;
 }
 
 static void
@@ -635,7 +635,7 @@ overwrite_prompt (char const *dst_path, 
       fprintf (stderr,
               _("%s: overwrite %s, overriding mode %04lo? "),
               program_name, quote (dst_path),
-              (unsigned long) (dst_sb->st_mode & CHMOD_MODE_BITS));
+              (unsigned long int) (dst_sb->st_mode & CHMOD_MODE_BITS));
     }
   else
     {
@@ -727,17 +727,16 @@ src_info_init (struct cp_options *x)
                       triple_free);
 }
 
-/* Return nonzero if there is an entry in hash table, HT,
-   for the file described by FILENAME and STATS.
-   Otherwise, return zero.  */
-static int
+/* Return true if there is an entry in hash table, HT,
+   for the file described by FILENAME and STATS.  */
+static bool
 seen_file (Hash_table const *ht, char const *filename,
           struct stat const *stats)
 {
   struct F_triple new_ent;
 
   if (ht == NULL)
-    return 0;
+    return false;
 
   new_ent.name = (char *) filename;
   new_ent.st_ino = stats->st_ino;
@@ -794,26 +793,26 @@ record_file (Hash_table *ht, char const 
 }
 
 /* Copy the file SRC_PATH to the file DST_PATH.  The files may be of
-   any type.  NEW_DST should be nonzero if the file DST_PATH cannot
+   any type.  NEW_DST should be true if the file DST_PATH cannot
    exist because its parent directory was just created; NEW_DST should
-   be zero if DST_PATH might already exist.  DEVICE is the device
+   be false if DST_PATH might already exist.  DEVICE is the device
    number of the parent directory, or 0 if the parent of this file is
    not known.  ANCESTORS points to a linked, null terminated list of
    devices and inodes of parent directories of SRC_PATH.  COMMAND_LINE_ARG
-   is nonzero iff SRC_PATH was specified on the command line.
-   Set *COPY_INTO_SELF to nonzero if SRC_PATH is a parent of (or the
-   same as) DST_PATH;  otherwise, set it to zero.
-   Return 0 if successful, 1 if an error occurs. */
+   is true iff SRC_PATH was specified on the command line.
+   Set *COPY_INTO_SELF if SRC_PATH is a parent of (or the
+   same as) DST_PATH; otherwise, clear it.
+   Return true if successful.  */
 
-static int
+static bool
 copy_internal (const char *src_path, const char *dst_path,
-              int new_dst,
+              bool new_dst,
               dev_t device,
               struct dir_list *ancestors,
               const struct cp_options *x,
-              int command_line_arg,
-              int *copy_into_self,
-              int *rename_succeeded)
+              bool command_line_arg,
+              bool *copy_into_self,
+              bool *rename_succeeded)
 {
   struct stat src_sb;
   struct stat dst_sb;
@@ -821,21 +820,21 @@ copy_internal (const char *src_path, con
   mode_t src_type;
   char *earlier_file = NULL;
   char *dst_backup = NULL;
-  int backup_succeeded = 0;
-  int delayed_fail;
-  int copied_as_regular = 0;
-  int ran_chown = 0;
-  int preserve_metadata;
+  bool backup_succeeded = false;
+  bool delayed_ok;
+  bool copied_as_regular = false;
+  bool ran_chown = false;
+  bool preserve_metadata;
 
   if (x->move_mode && rename_succeeded)
-    *rename_succeeded = 0;
+    *rename_succeeded = false;
 
-  *copy_into_self = 0;
+  *copy_into_self = false;
 
   if (XSTAT (x, src_path, &src_sb))
     {
       error (0, errno, _("cannot stat %s"), quote (src_path));
-      return 1;
+      return false;
     }
 
   src_type = src_sb.st_mode;
@@ -845,7 +844,7 @@ copy_internal (const char *src_path, con
   if (S_ISDIR (src_type) && !x->recursive)
     {
       error (0, 0, _("omitting directory %s"), quote (src_path));
-      return 1;
+      return false;
     }
 
   /* Detect the case in which the same source file appears more than
@@ -860,7 +859,7 @@ copy_internal (const char *src_path, con
        {
          error (0, 0, _("warning: source file %s specified more than once"),
                 quote (src_path));
-         return 0;
+         return true;
        }
 
       record_file (x->src_info, src_path, &src_sb);
@@ -873,39 +872,39 @@ copy_internal (const char *src_path, con
          if (errno != ENOENT)
            {
              error (0, errno, _("cannot stat %s"), quote (dst_path));
-             return 1;
+             return false;
            }
          else
            {
-             new_dst = 1;
+             new_dst = true;
            }
        }
       else
        {
-         int return_now;
-         int unlink_src;
-         int ok = same_file_ok (src_path, &src_sb, dst_path, &dst_sb,
-                                x, &return_now, &unlink_src);
+         bool return_now;
+         bool unlink_src;
+         bool ok = same_file_ok (src_path, &src_sb, dst_path, &dst_sb,
+                                 x, &return_now, &unlink_src);
          if (unlink_src)
            {
              if (unlink (src_path))
                {
                  error (0, errno, _("cannot remove %s"), quote (src_path));
-                 return 1;
+                 return false;
                }
              /* Tell the caller that there's no need to remove src_path.  */
              if (rename_succeeded)
-               *rename_succeeded = 1;
+               *rename_succeeded = true;
            }
 
          if (return_now)
-           return 0;
+           return true;
 
          if (! ok)
            {
              error (0, 0, _("%s and %s are the same file"),
                     quote_n (0, src_path), quote_n (1, dst_path));
-             return 1;
+             return false;
            }
 
          if (!S_ISDIR (dst_sb.st_mode))
@@ -915,7 +914,7 @@ copy_internal (const char *src_path, con
                  error (0, 0,
                     _("cannot overwrite non-directory %s with directory %s"),
                         quote_n (0, dst_path), quote_n (1, src_path));
-                 return 1;
+                 return false;
                }
 
              /* Don't let the user destroy their data, even if they try hard:
@@ -932,7 +931,7 @@ copy_internal (const char *src_path, con
                  error (0, 0,
                         _("will not overwrite just-created %s with %s"),
                         quote_n (0, dst_path), quote_n (1, src_path));
-                 return 1;
+                 return false;
                }
            }
 
@@ -943,7 +942,7 @@ copy_internal (const char *src_path, con
                  error (0, 0,
                       _("cannot overwrite directory %s with non-directory"),
                         quote (dst_path));
-                 return 1;
+                 return false;
                }
 
              if (x->update)
@@ -965,8 +964,8 @@ copy_internal (const char *src_path, con
                         rename succeeded, so the caller (if it's mv) doesn't
                         end up removing the source file.  */
                      if (rename_succeeded)
-                       *rename_succeeded = 1;
-                     return 0;
+                       *rename_succeeded = true;
+                     return true;
                    }
                }
            }
@@ -993,8 +992,8 @@ copy_internal (const char *src_path, con
                      /* Pretend the rename succeeded, so the caller (mv)
                         doesn't end up removing the source file.  */
                      if (rename_succeeded)
-                       *rename_succeeded = 1;
-                     return 0;
+                       *rename_succeeded = true;
+                     return true;
                    }
                }
              else
@@ -1004,7 +1003,7 @@ copy_internal (const char *src_path, con
                          && (overwrite_prompt (dst_path, &dst_sb), 1)
                          && ! yesno ()))
                    {
-                     return 0;
+                     return true;
                    }
                }
            }
@@ -1016,7 +1015,7 @@ copy_internal (const char *src_path, con
                {
                  error (0, 0, _("cannot overwrite directory %s"),
                         quote (dst_path));
-                 return 1;
+                 return false;
                }
 
              /* Don't allow user to move a directory onto a non-directory.  */
@@ -1025,7 +1024,7 @@ copy_internal (const char *src_path, con
                  error (0, 0,
                       _("cannot move directory onto non-directory: %s -> %s"),
                         quote_n (0, src_path), quote_n (0, dst_path));
-                 return 1;
+                 return false;
                }
            }
 
@@ -1050,7 +1049,7 @@ copy_internal (const char *src_path, con
                         quote_n (0, dst_path),
                         quote_n (1, src_path));
                  free (tmp_backup);
-                 return 1;
+                 return false;
                }
 
              /* FIXME: use fts:
@@ -1065,7 +1064,7 @@ copy_internal (const char *src_path, con
                  if (errno != ENOENT)
                    {
                      error (0, errno, _("cannot backup %s"), quote (dst_path));
-                     return 1;
+                     return false;
                    }
                  else
                    {
@@ -1074,9 +1073,9 @@ copy_internal (const char *src_path, con
                }
              else
                {
-                 backup_succeeded = 1;
+                 backup_succeeded = true;
                }
-             new_dst = 1;
+             new_dst = true;
            }
          else if (! S_ISDIR (dst_sb.st_mode)
                   && (x->unlink_dest_before_opening
@@ -1086,9 +1085,9 @@ copy_internal (const char *src_path, con
              if (unlink (dst_path) && errno != ENOENT)
                {
                  error (0, errno, _("cannot remove %s"), quote (dst_path));
-                 return 1;
+                 return false;
                }
-             new_dst = 1;
+             new_dst = true;
            }
        }
     }
@@ -1166,7 +1165,7 @@ copy_internal (const char *src_path, con
              error (0, 0, _("cannot copy a directory, %s, into itself, %s"),
                     quote_n (0, top_level_src_path),
                     quote_n (1, top_level_dst_path));
-             *copy_into_self = 1;
+             *copy_into_self = true;
            }
          else
            {
@@ -1178,9 +1177,7 @@ copy_internal (const char *src_path, con
        }
 
       {
-       int link_failed;
-
-       link_failed = link (earlier_file, dst_path);
+       bool link_failed = (link (earlier_file, dst_path) != 0);
 
        /* If the link failed because of an existing destination,
           remove that file and then call link again.  */
@@ -1191,7 +1188,7 @@ copy_internal (const char *src_path, con
                error (0, errno, _("cannot remove %s"), quote (dst_path));
                goto un_backup;
              }
-           link_failed = link (earlier_file, dst_path);
+           link_failed = (link (earlier_file, dst_path) != 0);
          }
 
        if (link_failed)
@@ -1201,7 +1198,7 @@ copy_internal (const char *src_path, con
            goto un_backup;
          }
 
-       return 0;
+       return true;
       }
     }
 
@@ -1212,7 +1209,7 @@ copy_internal (const char *src_path, con
          if (x->verbose && S_ISDIR (src_type))
            printf ("%s -> %s\n", quote_n (0, src_path), quote_n (1, dst_path));
          if (rename_succeeded)
-           *rename_succeeded = 1;
+           *rename_succeeded = true;
 
          if (command_line_arg)
            {
@@ -1226,7 +1223,7 @@ copy_internal (const char *src_path, con
              record_file (x->dest_info, dst_path, &src_sb);
            }
 
-         return 0;
+         return true;
        }
 
       /* FIXME: someday, consider what to do when moving a directory into
@@ -1258,11 +1255,11 @@ copy_internal (const char *src_path, con
             (compare with the other calls in this file) since the
             destination directory didn't exist before.  */
 
-         *copy_into_self = 1;
-         /* FIXME-cleanup: Don't return zero here; adjust mv.c accordingly.
+         *copy_into_self = true;
+         /* FIXME-cleanup: Don't return true here; adjust mv.c accordingly.
             The only caller that uses this code (mv.c) ends up setting its
             exit status to nonzero when copy_into_self is nonzero.  */
-         return 0;
+         return true;
        }
 
       /* WARNING: there probably exist systems for which an inter-device
@@ -1296,7 +1293,7 @@ copy_internal (const char *src_path, con
                 _("cannot move %s to %s"),
                 quote_n (0, src_path), quote_n (1, dst_path));
          forget_created (src_sb.st_ino, src_sb.st_dev);
-         return 1;
+         return false;
        }
 
       /* The rename attempt has failed.  Remove any existing destination
@@ -1308,19 +1305,19 @@ copy_internal (const char *src_path, con
             _("inter-device move failed: %s to %s; unable to remove target"),
                 quote_n (0, src_path), quote_n (1, dst_path));
          forget_created (src_sb.st_ino, src_sb.st_dev);
-         return 1;
+         return false;
        }
 
-      new_dst = 1;
+      new_dst = true;
     }
 
-  delayed_fail = 0;
+  delayed_ok = true;
 
   /* In certain modes (cp's --symbolic-link), and for certain file types
      (symlinks and hard links) it doesn't make sense to preserve metadata,
      or it's possible to preserve only some of it.
      In such cases, set this variable to zero.  */
-  preserve_metadata = 1;
+  preserve_metadata = true;
 
   if (S_ISDIR (src_type))
     {
@@ -1361,7 +1358,7 @@ copy_internal (const char *src_path, con
              numbers into the search structure, so that we can
              avoid copying it again.  */
 
-         if (remember_created (dst_path))
+         if (! remember_created (dst_path))
            goto un_backup;
 
          if (x->verbose)
@@ -1370,23 +1367,23 @@ copy_internal (const char *src_path, con
 
       /* Are we crossing a file system boundary?  */
       if (x->one_file_system && device != 0 && device != src_sb.st_dev)
-       return 0;
+       return true;
 
       /* Copy the contents of the directory.  */
 
-      if (copy_dir (src_path, dst_path, new_dst, &src_sb, dir, x,
-                   copy_into_self))
+      if (! copy_dir (src_path, dst_path, new_dst, &src_sb, dir, x,
+                     copy_into_self))
        {
          /* Don't just return here -- otherwise, the failure to read a
             single file in a source directory would cause the containing
             destination directory not to have owner/perms set properly.  */
-         delayed_fail = 1;
+         delayed_ok = false;
        }
     }
 #ifdef S_ISLNK
   else if (x->symbolic_link)
     {
-      preserve_metadata = 0;
+      preserve_metadata = false;
 
       if (*src_path != '/')
        {
@@ -1394,7 +1391,7 @@ copy_internal (const char *src_path, con
          struct stat dot_sb;
          struct stat dst_parent_sb;
          char *dst_parent;
-         int in_current_dir;
+         bool in_current_dir;
 
          dst_parent = dir_name (dst_path);
 
@@ -1425,7 +1422,7 @@ copy_internal (const char *src_path, con
 #endif
   else if (x->hard_link)
     {
-      preserve_metadata = 0;
+      preserve_metadata = false;
       if (link (src_path, dst_path))
        {
          error (0, errno, _("cannot create link %s"), quote (dst_path));
@@ -1436,12 +1433,12 @@ copy_internal (const char *src_path, con
           || (x->copy_as_regular && !S_ISDIR (src_type)
               && !S_ISLNK (src_type)))
     {
-      copied_as_regular = 1;
+      copied_as_regular = true;
       /* POSIX says the permission bits of the source file must be
         used as the 3rd argument in the open call, but that's not consistent
         with historical practice.  */
-      if (copy_reg (src_path, dst_path, x,
-                   get_dest_mode (x, src_mode), &new_dst, &src_sb))
+      if (! copy_reg (src_path, dst_path, x,
+                     get_dest_mode (x, src_mode), &new_dst, &src_sb))
        goto un_backup;
     }
   else
@@ -1506,7 +1503,7 @@ copy_internal (const char *src_path, con
        }
 
       /* There's no need to preserve timestamps or permissions.  */
-      preserve_metadata = 0;
+      preserve_metadata = false;
 
       if (x->preserve_ownership)
        {
@@ -1538,7 +1535,7 @@ copy_internal (const char *src_path, con
     record_file (x->dest_info, dst_path, NULL);
 
   if ( ! preserve_metadata)
-    return 0;
+    return true;
 
   /* POSIX says that `cp -p' must restore the following:
      - permission bits
@@ -1565,7 +1562,7 @@ copy_internal (const char *src_path, con
        {
          error (0, errno, _("preserving times for %s"), quote (dst_path));
          if (x->require_preserve)
-           return 1;
+           return false;
        }
     }
 
@@ -1573,13 +1570,13 @@ copy_internal (const char *src_path, con
   if (x->preserve_ownership
       && (new_dst || !SAME_OWNER_AND_GROUP (src_sb, dst_sb)))
     {
-      ran_chown = 1;
+      ran_chown = true;
       if (DO_CHOWN (chown, dst_path, src_sb.st_uid, src_sb.st_gid))
        {
          error (0, errno, _("failed to preserve ownership for %s"),
                 quote (dst_path));
          if (x->require_preserve)
-           return 1;
+           return false;
        }
     }
 
@@ -1605,7 +1602,7 @@ copy_internal (const char *src_path, con
      we had to run chown, because the chown must have reset those bits.  */
   if ((new_dst && copied_as_regular)
       && !(ran_chown && (src_mode & ~S_IRWXUGO)))
-    return delayed_fail;
+    return delayed_ok;
 
   if ((x->preserve_mode || new_dst)
       && (x->copy_as_regular || S_ISREG (src_type) || S_ISDIR (src_type)))
@@ -1614,11 +1611,11 @@ copy_internal (const char *src_path, con
        {
          error (0, errno, _("setting permissions for %s"), quote (dst_path));
          if (x->set_mode || x->require_preserve)
-           return 1;
+           return false;
        }
     }
 
-  return delayed_fail;
+  return delayed_ok;
 
 un_backup:
 
@@ -1642,31 +1639,31 @@ un_backup:
                    quote_n (0, dst_backup), quote_n (1, dst_path));
        }
     }
-  return 1;
+  return false;
 }
 
-static int
+static bool
 valid_options (const struct cp_options *co)
 {
   assert (co != NULL);
   assert (VALID_BACKUP_TYPE (co->backup_type));
   assert (VALID_SPARSE_MODE (co->sparse_mode));
-  return 1;
+  return true;
 }
 
 /* Copy the file SRC_PATH to the file DST_PATH.  The files may be of
-   any type.  NONEXISTENT_DST should be nonzero if the file DST_PATH
+   any type.  NONEXISTENT_DST should be true if the file DST_PATH
    is known not to exist (e.g., because its parent directory was just
-   created);  NONEXISTENT_DST should be zero if DST_PATH might already
+   created);  NONEXISTENT_DST should be false if DST_PATH might already
    exist.  OPTIONS is ... FIXME-describe
-   Set *COPY_INTO_SELF to nonzero if SRC_PATH is a parent of (or the
-   same as) DST_PATH;  otherwise, set it to zero.
-   Return 0 if successful, 1 if an error occurs. */
+   Set *COPY_INTO_SELF if SRC_PATH is a parent of (or the
+   same as) DST_PATH; otherwise, set clear it.
+   Return true if successful.  */
 
-extern int
+bool
 copy (const char *src_path, const char *dst_path,
-      int nonexistent_dst, const struct cp_options *options,
-      int *copy_into_self, int *rename_succeeded)
+      bool nonexistent_dst, const struct cp_options *options,
+      bool *copy_into_self, bool *rename_succeeded)
 {
   assert (valid_options (options));
 
@@ -1681,5 +1678,5 @@ copy (const char *src_path, const char *
   top_level_dst_path = dst_path;
 
   return copy_internal (src_path, dst_path, nonexistent_dst, 0, NULL,
-                       options, 1, copy_into_self, rename_succeeded);
+                       options, true, copy_into_self, rename_succeeded);
 }
Index: cp-hash.h
===================================================================
RCS file: /home/eggert/coreutils/cu/src/cp-hash.h,v
retrieving revision 1.7
diff -p -u -r1.7 cp-hash.h
--- cp-hash.h   12 Mar 2004 11:53:46 -0000      1.7
+++ cp-hash.h   15 Jul 2004 18:27:57 -0000
@@ -2,5 +2,5 @@ void hash_init (void);
 void forget_all (void);
 void forget_created (ino_t ino, dev_t dev);
 char *remember_copied (const char *node, ino_t ino, dev_t dev);
-int remember_created (const char *path);
+bool remember_created (const char *path);
 char *src_to_dest_lookup (ino_t ino, dev_t dev);
Index: cp-hash.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/cp-hash.c,v
retrieving revision 1.32
diff -p -u -r1.32 cp-hash.c
--- cp-hash.c   27 Apr 2004 15:02:11 -0000      1.32
+++ cp-hash.c   15 Jul 2004 18:27:37 -0000
@@ -99,9 +99,9 @@ forget_created (ino_t ino, dev_t dev)
 }
 
 /* Add PATH to the list of files that we have created.
-   Return 1 if we can't stat PATH, otherwise 0.  */
+   Return true if successful.  */
 
-extern int
+bool
 remember_created (const char *path)
 {
   struct stat sb;
@@ -109,11 +109,11 @@ remember_created (const char *path)
   if (stat (path, &sb) < 0)
     {
       error (0, errno, "%s", quote (path));
-      return 1;
+      return false;
     }
 
   remember_copied (path, sb.st_ino, sb.st_dev);
-  return 0;
+  return true;
 }
 
 /* If INO/DEV correspond to an already-copied source file, return the
Index: cp.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/cp.c,v
retrieving revision 1.200
diff -p -u -r1.200 cp.c
--- cp.c        27 Jul 2004 23:14:05 -0000      1.200
+++ cp.c        28 Jul 2004 23:45:02 -0000
@@ -59,8 +59,8 @@ uid_t geteuid ();
    need to be fixed after copying. */
 struct dir_attr
 {
-  int is_new_dir;
-  int slash_offset;
+  bool is_new_dir;
+  size_t slash_offset;
   struct dir_attr *next;
 };
 
@@ -87,12 +87,12 @@ enum
 /* The invocation name of this program.  */
 char *program_name;
 
-/* If nonzero, the command "cp x/e_file e_dir" uses "e_dir/x/e_file"
+/* If true, the command "cp x/e_file e_dir" uses "e_dir/x/e_file"
    as its destination instead of the usual "e_dir/e_file." */
-static int flag_path = 0;
+static bool flag_path = false;
 
 /* Remove any trailing slashes from each SOURCE argument.  */
-static int remove_trailing_slashes;
+static bool remove_trailing_slashes;
 
 static char const *const sparse_type_string[] =
 {
@@ -271,12 +271,12 @@ regular file.\n\
    the corresponding source directories regardless of whether they
    existed before the `cp' command was given.
 
-   Return 0 if the parent of CONST_DST_PATH and any intermediate
+   Return true if the parent of CONST_DST_PATH and any intermediate
    directories specified by ATTR_LIST have the proper permissions
-   when done, otherwise 1. */
+   when done.  */
 
-static int
-re_protect (const char *const_dst_path, int src_offset,
+static bool
+re_protect (const char *const_dst_path, size_t src_offset,
            struct dir_attr *attr_list, const struct cp_options *x)
 {
   struct dir_attr *p;
@@ -297,7 +297,7 @@ re_protect (const char *const_dst_path, 
        {
          error (0, errno, _("failed to get attributes of %s"),
                 quote (src_path));
-         return 1;
+         return false;
        }
 
       /* Adjust the times (and if possible, ownership) for the copy.
@@ -317,7 +317,7 @@ re_protect (const char *const_dst_path, 
            {
              error (0, errno, _("failed to preserve times for %s"),
                     quote (dst_path));
-             return 1;
+             return false;
            }
        }
 
@@ -331,23 +331,23 @@ re_protect (const char *const_dst_path, 
            {
              error (0, errno, _("failed to preserve ownership for %s"),
                     quote (dst_path));
-             return 1;
+             return false;
            }
        }
 
-      if (x->preserve_mode || p->is_new_dir)
+      if (x->preserve_mode | p->is_new_dir)
        {
          if (chmod (dst_path, src_sb.st_mode & x->umask_kill))
            {
              error (0, errno, _("failed to preserve permissions for %s"),
                     quote (dst_path));
-             return 1;
+             return false;
            }
        }
 
       dst_path[p->slash_offset] = '/';
     }
-  return 0;
+  return true;
 }
 
 /* Ensure that the parent directory of CONST_DIRPATH exists, for
@@ -363,17 +363,17 @@ re_protect (const char *const_dst_path, 
    source and destination directories.
    Creates a linked list of attributes of intermediate directories,
    *ATTR_LIST, for re_protect to use after calling copy.
-   Sets *NEW_DST to 1 if this function creates parent of CONST_DIRPATH.
+   Sets *NEW_DST if this function creates parent of CONST_DIRPATH.
 
-   Return 0 if parent of CONST_DIRPATH exists as a directory with the proper
-   permissions when done, otherwise 1. */
+   Return true if parent of CONST_DIRPATH exists as a directory with the proper
+   permissions when done.  */
 
 /* FIXME: find a way to synch this function with the one in lib/makepath.c. */
 
-static int
-make_path_private (const char *const_dirpath, size_t src_offset, int mode,
+static bool
+make_path_private (const char *const_dirpath, size_t src_offset, mode_t mode,
                   const char *verbose_fmt_string, struct dir_attr **attr_list,
-                  int *new_dst, int (*xstat)())
+                  bool *new_dst, int (*xstat)())
 {
   struct stat stats;
   char *dirpath;               /* A copy of CONST_DIRPATH we can change. */
@@ -418,13 +418,13 @@ make_path_private (const char *const_dir
                 for example, in the command `cp --parents ../a/../b/c e_dir',
                 make_path_private creates only e_dir/../a if ./b already
                 exists. */
-             *new_dst = 1;
-             new->is_new_dir = 1;
+             *new_dst = true;
+             new->is_new_dir = true;
              if (mkdir (dirpath, mode))
                {
                  error (0, errno, _("cannot make directory %s"),
                         quote (dirpath));
-                 return 1;
+                 return false;
                }
              else
                {
@@ -436,12 +436,12 @@ make_path_private (const char *const_dir
            {
              error (0, 0, _("%s exists but is not a directory"),
                     quote (dirpath));
-             return 1;
+             return false;
            }
          else
            {
-             new->is_new_dir = 0;
-             *new_dst = 0;
+             new->is_new_dir = false;
+             *new_dst = false;
            }
          *slash++ = '/';
 
@@ -457,50 +457,53 @@ make_path_private (const char *const_dir
   else if (!S_ISDIR (stats.st_mode))
     {
       error (0, 0, _("%s exists but is not a directory"), quote (dst_dirname));
-      return 1;
+      return false;
     }
   else
     {
-      *new_dst = 0;
+      *new_dst = false;
     }
-  return 0;
+  return true;
 }
 
-/* FILE is the last operand of this command.  Return -1 if FILE is a
-   directory, 0 if not, ENOENT if FILE does not exist.
-   But report an error there is a problem accessing FILE,
+/* FILE is the last operand of this command.
+   Return true if FILE is a directory.
+   But report an error and exit if there is a problem accessing FILE,
    or if FILE does not exist but would have to refer to an existing
    directory if it referred to anything at all.
 
-   Store the file's status into *ST, and store the resulting
-   error number into *ERRP.  */
+   If the file exists, store the file's status into *ST.
+   Otherwise, set *NEW_DST.  */
 
-static int
-target_directory_operand (char const *file, struct stat *st, int *errp)
+static bool
+target_directory_operand (char const *file, struct stat *st, bool *new_dst)
 {
   char const *b = base_name (file);
   size_t blen = strlen (b);
   bool looks_like_a_dir = (blen == 0 || ISSLASH (b[blen - 1]));
   int err = (stat (file, st) == 0 ? 0 : errno);
   bool is_a_dir = !err && S_ISDIR (st->st_mode);
-  if (err && err != ENOENT)
-    error (EXIT_FAILURE, err, _("accessing %s"), quote (file));
+  if (err)
+    {
+      if (err != ENOENT)
+       error (EXIT_FAILURE, err, _("accessing %s"), quote (file));
+      *new_dst = true;
+    }
   if (is_a_dir < looks_like_a_dir)
     error (EXIT_FAILURE, err, _("target %s is not a directory"), quote (file));
-  *errp = err;
   return is_a_dir;
 }
 
 /* Scan the arguments, and copy each by calling copy.
-   Return 0 if successful, 1 if any errors occur. */
+   Return true if successful.  */
 
-static int
+static bool
 do_copy (int n_files, char **file, const char *target_directory,
         bool no_target_directory, struct cp_options *x)
 {
   struct stat sb;
-  int new_dst = 0;
-  int ret = 0;
+  bool new_dst = false;
+  bool ok = true;
 
   if (n_files <= !target_directory)
     {
@@ -557,7 +560,7 @@ do_copy (int n_files, char **file, const
       for (i = 0; i < n_files; i++)
        {
          char *dst_path;
-         int parent_exists = 1; /* True if dir_name (dst_path) exists. */
+         bool parent_exists = true;  /* True if dir_name (dst_path) exists. */
          struct dir_attr *attr_list;
          char *arg_in_concat = NULL;
          char *arg = file[i];
@@ -586,13 +589,13 @@ do_copy (int n_files, char **file, const
              /* For --parents, we have to make sure that the directory
                 dir_name (dst_path) exists.  We may have to create a few
                 leading directories. */
-             parent_exists = !make_path_private (dst_path,
-                                                 arg_in_concat - dst_path,
-                                                 S_IRWXU,
-                                                 (x->verbose
-                                                  ? "%s -> %s\n" : NULL),
-                                                 &attr_list, &new_dst,
-                                                 xstat);
+             parent_exists = make_path_private (dst_path,
+                                                arg_in_concat - dst_path,
+                                                S_IRWXU,
+                                                (x->verbose
+                                                 ? "%s -> %s\n" : NULL),
+                                                &attr_list, &new_dst,
+                                                xstat);
            }
          else
            {
@@ -609,30 +612,27 @@ do_copy (int n_files, char **file, const
          if (!parent_exists)
            {
              /* make_path_private failed, so don't even attempt the copy. */
-             ret = 1;
+             ok = false;
            }
          else
            {
-             int copy_into_self;
-             ret |= copy (arg, dst_path, new_dst, x, &copy_into_self, NULL);
+             bool copy_into_self;
+             ok &= copy (arg, dst_path, new_dst, x, &copy_into_self, NULL);
 
              if (flag_path)
-               {
-                 ret |= re_protect (dst_path, arg_in_concat - dst_path,
-                                    attr_list, x);
-               }
+               ok &= re_protect (dst_path, arg_in_concat - dst_path,
+                                 attr_list, x);
            }
 
          free (dst_path);
        }
-      return ret;
     }
   else /* !target_directory */
     {
       char const *new_dest;
       char const *source = file[0];
       char const *dest = file[1];
-      int unused;
+      bool unused;
 
       if (flag_path)
        {
@@ -669,39 +669,39 @@ do_copy (int n_files, char **file, const
          new_dest = dest;
        }
 
-      return copy (source, new_dest, 0, x, &unused, NULL);
+      ok = copy (source, new_dest, 0, x, &unused, NULL);
     }
 
-  /* unreachable */
+  return ok;
 }
 
 static void
 cp_option_init (struct cp_options *x)
 {
-  x->copy_as_regular = 1;
+  x->copy_as_regular = true;
   x->dereference = DEREF_UNDEFINED;
-  x->unlink_dest_before_opening = 0;
-  x->unlink_dest_after_failed_open = 0;
-  x->hard_link = 0;
+  x->unlink_dest_before_opening = false;
+  x->unlink_dest_after_failed_open = false;
+  x->hard_link = false;
   x->interactive = I_UNSPECIFIED;
   x->myeuid = geteuid ();
-  x->move_mode = 0;
-  x->one_file_system = 0;
+  x->move_mode = false;
+  x->one_file_system = false;
 
-  x->preserve_ownership = 0;
-  x->preserve_links = 0;
-  x->preserve_mode = 0;
-  x->preserve_timestamps = 0;
+  x->preserve_ownership = false;
+  x->preserve_links = false;
+  x->preserve_mode = false;
+  x->preserve_timestamps = false;
 
-  x->require_preserve = 0;
-  x->recursive = 0;
+  x->require_preserve = false;
+  x->recursive = false;
   x->sparse_mode = SPARSE_AUTO;
-  x->symbolic_link = 0;
-  x->set_mode = 0;
+  x->symbolic_link = false;
+  x->set_mode = false;
   x->mode = 0;
 
   /* Not used.  */
-  x->stdin_tty = 0;
+  x->stdin_tty = false;
 
   /* Find out the current file creation mask, to knock the right bits
      when using chmod.  The creation mask is set to be liberal, so
@@ -709,8 +709,8 @@ cp_option_init (struct cp_options *x)
      have been allowed with the mask this process was started with.  */
   x->umask_kill = ~ umask (0);
 
-  x->update = 0;
-  x->verbose = 0;
+  x->update = false;
+  x->verbose = false;
   x->dest_info = NULL;
   x->src_info = NULL;
 }
@@ -718,7 +718,7 @@ cp_option_init (struct cp_options *x)
 /* Given a string, ARG, containing a comma-separated list of arguments
    to the --preserve option, set the appropriate fields of X to ON_OFF.  */
 static void
-decode_preserve_arg (char const *arg, struct cp_options *x, int on_off)
+decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
 {
   enum File_attribute
     {
@@ -794,12 +794,12 @@ int
 main (int argc, char **argv)
 {
   int c;
-  int exit_status;
-  int make_backups = 0;
+  bool ok;
+  bool make_backups = false;
   char *backup_suffix_string;
   char *version_control_string = NULL;
   struct cp_options x;
-  int copy_contents = 0;
+  bool copy_contents = false;
   char *target_directory = NULL;
   bool no_target_directory = false;
 
@@ -833,12 +833,12 @@ main (int argc, char **argv)
 
        case 'a':               /* Like -dpPR. */
          x.dereference = DEREF_NEVER;
-         x.preserve_links = 1;
-         x.preserve_ownership = 1;
-         x.preserve_mode = 1;
-         x.preserve_timestamps = 1;
-         x.require_preserve = 1;
-         x.recursive = 1;
+         x.preserve_links = true;
+         x.preserve_ownership = true;
+         x.preserve_mode = true;
+         x.preserve_timestamps = true;
+         x.require_preserve = true;
+         x.recursive = true;
          break;
 
        case 'V':  /* FIXME: this is deprecated.  Remove it in 2001.  */
@@ -849,22 +849,22 @@ main (int argc, char **argv)
          /* Fall through.  */
 
        case 'b':
-         make_backups = 1;
+         make_backups = true;
          if (optarg)
            version_control_string = optarg;
          break;
 
        case COPY_CONTENTS_OPTION:
-         copy_contents = 1;
+         copy_contents = true;
          break;
 
        case 'd':
-         x.preserve_links = 1;
+         x.preserve_links = true;
          x.dereference = DEREF_NEVER;
          break;
 
        case 'f':
-         x.unlink_dest_after_failed_open = 1;
+         x.unlink_dest_after_failed_open = true;
          break;
 
        case 'H':
@@ -876,7 +876,7 @@ main (int argc, char **argv)
          break;
 
        case 'l':
-         x.hard_link = 1;
+         x.hard_link = true;
          break;
 
        case 'L':
@@ -888,7 +888,7 @@ main (int argc, char **argv)
          break;
 
        case NO_PRESERVE_ATTRIBUTES_OPTION:
-         decode_preserve_arg (optarg, &x, 0);
+         decode_preserve_arg (optarg, &x, false);
          break;
 
        case PRESERVE_ATTRIBUTES_OPTION:
@@ -898,25 +898,25 @@ main (int argc, char **argv)
            }
          else
            {
-             decode_preserve_arg (optarg, &x, 1);
-             x.require_preserve = 1;
+             decode_preserve_arg (optarg, &x, true);
+             x.require_preserve = true;
              break;
            }
 
        case 'p':
-         x.preserve_ownership = 1;
-         x.preserve_mode = 1;
-         x.preserve_timestamps = 1;
-         x.require_preserve = 1;
+         x.preserve_ownership = true;
+         x.preserve_mode = true;
+         x.preserve_timestamps = true;
+         x.require_preserve = true;
          break;
 
        case PARENTS_OPTION:
-         flag_path = 1;
+         flag_path = true;
          break;
 
        case 'r':
        case 'R':
-         x.recursive = 1;
+         x.recursive = true;
          break;
 
        case REPLY_OPTION:
@@ -925,16 +925,16 @@ main (int argc, char **argv)
          break;
 
        case UNLINK_DEST_BEFORE_OPENING:
-         x.unlink_dest_before_opening = 1;
+         x.unlink_dest_before_opening = true;
          break;
 
        case STRIP_TRAILING_SLASHES_OPTION:
-         remove_trailing_slashes = 1;
+         remove_trailing_slashes = true;
          break;
 
        case 's':
 #ifdef S_ISLNK
-         x.symbolic_link = 1;
+         x.symbolic_link = true;
 #else
          error (EXIT_FAILURE, 0,
                 _("symbolic links are not supported on this system"));
@@ -962,19 +962,19 @@ main (int argc, char **argv)
          break;
 
        case 'u':
-         x.update = 1;
+         x.update = true;
          break;
 
        case 'v':
-         x.verbose = 1;
+         x.verbose = true;
          break;
 
        case 'x':
-         x.one_file_system = 1;
+         x.one_file_system = true;
          break;
 
        case 'S':
-         make_backups = 1;
+         make_backups = true;
          backup_suffix_string = optarg;
          break;
 
@@ -987,7 +987,7 @@ main (int argc, char **argv)
        }
     }
 
-  if (x.hard_link && x.symbolic_link)
+  if (x.hard_link & x.symbolic_link)
     {
       error (0, 0, _("cannot make both hard and symbolic links"));
       usage (EXIT_FAILURE);
@@ -1001,7 +1001,7 @@ main (int argc, char **argv)
                                   version_control_string)
                   : none);
 
-  if (x.preserve_mode == 1)
+  if (x.preserve_mode)
     x.umask_kill = ~ (mode_t) 0;
 
   if (x.dereference == DEREF_UNDEFINED)
@@ -1021,17 +1021,17 @@ main (int argc, char **argv)
 
   /* If --force (-f) was specified and we're in link-creation mode,
      first remove any existing destination file.  */
-  if (x.unlink_dest_after_failed_open && (x.hard_link || x.symbolic_link))
-    x.unlink_dest_before_opening = 1;
+  if (x.unlink_dest_after_failed_open & (x.hard_link | x.symbolic_link))
+    x.unlink_dest_before_opening = true;
 
   /* Allocate space for remembering copied and created files.  */
 
   hash_init ();
 
-  exit_status = do_copy (argc - optind, argv + optind,
-                        target_directory, no_target_directory, &x);
+  ok = do_copy (argc - optind, argv + optind,
+               target_directory, no_target_directory, &x);
 
   forget_all ();
 
-  exit (exit_status);
+  exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
Index: install.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/install.c,v
retrieving revision 1.163
diff -p -u -r1.163 install.c
--- install.c   2 Jul 2004 17:01:08 -0000       1.163
+++ install.c   17 Jul 2004 06:01:28 -0000
@@ -72,20 +72,20 @@ gid_t getgid ();
 /* Number of bytes of a file to copy at a time. */
 #define READ_SIZE (32 * 1024)
 
-int isdir ();
+bool isdir (char const *);
 
 int stat ();
 
-static int change_timestamps (const char *from, const char *to);
-static int change_attributes (const char *path);
-static int copy_file (const char *from, const char *to,
-                     const struct cp_options *x);
-static int install_file_to_path (const char *from, const char *to,
-                                const struct cp_options *x);
-static int install_file_in_dir (const char *from, const char *to_dir,
-                               const struct cp_options *x);
-static int install_file_in_file (const char *from, const char *to,
+static bool change_timestamps (const char *from, const char *to);
+static bool change_attributes (const char *path);
+static bool copy_file (const char *from, const char *to,
+                      const struct cp_options *x);
+static bool install_file_to_path (const char *from, const char *to,
+                                 const struct cp_options *x);
+static bool install_file_in_dir (const char *from, const char *to_dir,
                                 const struct cp_options *x);
+static bool install_file_in_file (const char *from, const char *to,
+                                 const struct cp_options *x);
 static void get_ids (void);
 static void strip (const char *path);
 void usage (int status);
@@ -111,11 +111,11 @@ static gid_t group_id;
    no effect. */
 static mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
 
-/* If nonzero, strip executable files after copying them. */
-static int strip_files;
+/* If true, strip executable files after copying them. */
+static bool strip_files;
 
-/* If nonzero, install a directory instead of a regular file. */
-static int dir_arg;
+/* If true, install a directory instead of a regular file. */
+static bool dir_arg;
 
 static struct option const long_options[] =
 {
@@ -139,35 +139,35 @@ static struct option const long_options[
 static void
 cp_option_init (struct cp_options *x)
 {
-  x->copy_as_regular = 1;
+  x->copy_as_regular = true;
   x->dereference = DEREF_ALWAYS;
-  x->unlink_dest_before_opening = 1;
-  x->unlink_dest_after_failed_open = 0;
-  x->hard_link = 0;
+  x->unlink_dest_before_opening = true;
+  x->unlink_dest_after_failed_open = false;
+  x->hard_link = false;
   x->interactive = I_UNSPECIFIED;
-  x->move_mode = 0;
+  x->move_mode = false;
   x->myeuid = geteuid ();
-  x->one_file_system = 0;
-  x->preserve_ownership = 0;
-  x->preserve_links = 0;
-  x->preserve_mode = 0;
-  x->preserve_timestamps = 0;
-  x->require_preserve = 0;
-  x->recursive = 0;
+  x->one_file_system = false;
+  x->preserve_ownership = false;
+  x->preserve_links = false;
+  x->preserve_mode = false;
+  x->preserve_timestamps = false;
+  x->require_preserve = false;
+  x->recursive = false;
   x->sparse_mode = SPARSE_AUTO;
-  x->symbolic_link = 0;
+  x->symbolic_link = false;
   x->backup_type = none;
 
   /* Create destination files initially writable so we can run strip on them.
      Although GNU strip works fine on read-only files, some others
      would fail.  */
-  x->set_mode = 1;
+  x->set_mode = true;
   x->mode = S_IRUSR | S_IWUSR;
-  x->stdin_tty = 0;
+  x->stdin_tty = false;
 
   x->umask_kill = 0;
-  x->update = 0;
-  x->verbose = 0;
+  x->update = false;
+  x->verbose = false;
   x->dest_info = NULL;
   x->src_info = NULL;
 }
@@ -197,12 +197,12 @@ int
 main (int argc, char **argv)
 {
   int optc;
-  int errors = 0;
+  bool ok = true;
   const char *specified_mode = NULL;
-  int make_backups = 0;
+  bool make_backups = false;
   char *backup_suffix_string;
   char *version_control_string = NULL;
-  int mkdir_and_install = 0;
+  bool mkdir_and_install = false;
   struct cp_options x;
   char const *target_directory = NULL;
   bool no_target_directory = false;
@@ -221,8 +221,8 @@ main (int argc, char **argv)
 
   owner_name = NULL;
   group_name = NULL;
-  strip_files = 0;
-  dir_arg = 0;
+  strip_files = false;
+  dir_arg = false;
   umask (0);
 
   /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
@@ -245,27 +245,27 @@ main (int argc, char **argv)
          /* Fall through.  */
 
        case 'b':
-         make_backups = 1;
+         make_backups = true;
          if (optarg)
            version_control_string = optarg;
          break;
        case 'c':
          break;
        case 's':
-         strip_files = 1;
+         strip_files = true;
 #ifdef SIGCHLD
          /* System V fork+wait does not work if SIGCHLD is ignored.  */
          signal (SIGCHLD, SIG_DFL);
 #endif
          break;
        case 'd':
-         dir_arg = 1;
+         dir_arg = true;
          break;
        case 'D':
-         mkdir_and_install = 1;
+         mkdir_and_install = true;
          break;
        case 'v':
-         x.verbose = 1;
+         x.verbose = true;
          break;
        case 'g':
          group_name = optarg;
@@ -277,10 +277,10 @@ main (int argc, char **argv)
          owner_name = optarg;
          break;
        case 'p':
-         x.preserve_timestamps = 1;
+         x.preserve_timestamps = true;
          break;
        case 'S':
-         make_backups = 1;
+         make_backups = true;
          backup_suffix_string = optarg;
          break;
        case 't':
@@ -309,7 +309,7 @@ main (int argc, char **argv)
     }
 
   /* Check for invalid combinations of arguments. */
-  if (dir_arg && strip_files)
+  if (dir_arg & strip_files)
     error (EXIT_FAILURE, 0,
           _("the strip option may not be used when installing a directory"));
   if (dir_arg && target_directory)
@@ -375,8 +375,8 @@ main (int argc, char **argv)
       int i;
       for (i = 0; i < n_files; i++)
        {
-         errors |=
-           make_path (file[i], mode, mode, owner_id, group_id, 0,
+         ok &=
+           make_path (file[i], mode, mode, owner_id, group_id, false,
                       (x.verbose ? _("creating directory %s") : NULL));
        }
     }
@@ -389,9 +389,9 @@ main (int argc, char **argv)
       if (!target_directory)
         {
           if (mkdir_and_install)
-           errors = install_file_to_path (file[0], file[1], &x);
+           ok = install_file_to_path (file[0], file[1], &x);
          else
-           errors = install_file_in_file (file[0], file[1], &x);
+           ok = install_file_in_file (file[0], file[1], &x);
        }
       else
        {
@@ -399,23 +399,23 @@ main (int argc, char **argv)
          dest_info_init (&x);
          for (i = 0; i < n_files; i++)
            {
-             errors |= install_file_in_dir (file[i], target_directory, &x);
+             ok &= install_file_in_dir (file[i], target_directory, &x);
            }
        }
     }
 
-  exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
+  exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
 /* Copy file FROM onto file TO, creating any missing parent directories of TO.
-   Return 0 if successful, 1 if an error occurs */
+   Return true if successful.  */
 
-static int
+static bool
 install_file_to_path (const char *from, const char *to,
                      const struct cp_options *x)
 {
   char *dest_dir;
-  int fail = 0;
+  bool ok = true;
 
   dest_dir = dir_name (to);
 
@@ -428,65 +428,59 @@ install_file_to_path (const char *from, 
         that this option is intended mainly to help installers when the
         distribution doesn't provide proper install rules.  */
 #define DIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
-      fail = make_path (dest_dir, DIR_MODE, DIR_MODE, owner_id, group_id, 0,
-                       (x->verbose ? _("creating directory %s") : NULL));
+      ok = make_path (dest_dir, DIR_MODE, DIR_MODE, owner_id, group_id, false,
+                     (x->verbose ? _("creating directory %s") : NULL));
     }
 
-  if (fail == 0)
-    fail = install_file_in_file (from, to, x);
+  if (ok)
+    ok = install_file_in_file (from, to, x);
 
   free (dest_dir);
 
-  return fail;
+  return ok;
 }
 
 /* Copy file FROM onto file TO and give TO the appropriate
    attributes.
-   Return 0 if successful, 1 if an error occurs. */
+   Return true if successful.  */
 
-static int
+static bool
 install_file_in_file (const char *from, const char *to,
                      const struct cp_options *x)
 {
-  if (copy_file (from, to, x))
-    return 1;
+  if (! copy_file (from, to, x))
+    return false;
   if (strip_files)
     strip (to);
-  if (change_attributes (to))
-    return 1;
+  if (! change_attributes (to))
+    return false;
   if (x->preserve_timestamps)
     return change_timestamps (from, to);
-  return 0;
+  return true;
 }
 
 /* Copy file FROM into directory TO_DIR, keeping its same name,
    and give the copy the appropriate attributes.
-   Return 0 if successful, 1 if not. */
+   Return true if successful.  */
 
-static int
+static bool
 install_file_in_dir (const char *from, const char *to_dir,
                     const struct cp_options *x)
 {
-  const char *from_base;
-  char *to;
-  int ret;
-
-  from_base = base_name (from);
-  to = path_concat (to_dir, from_base, NULL);
-  ret = install_file_in_file (from, to, x);
+  const char *from_base = base_name (from);
+  char *to = path_concat (to_dir, from_base, NULL);
+  bool ret = install_file_in_file (from, to, x);
   free (to);
   return ret;
 }
 
 /* Copy file FROM onto file TO, creating TO if necessary.
-   Return 0 if the copy is successful, 1 if not.  */
+   Return true if successful.  */
 
-static int
+static bool
 copy_file (const char *from, const char *to, const struct cp_options *x)
 {
-  int fail;
-  int nonexistent_dst = 0;
-  int copy_into_self;
+  bool copy_into_self;
 
   /* Allow installing from non-regular files like /dev/null.
      Charles Karney reported that some Sun version of install allows that
@@ -494,21 +488,19 @@ copy_file (const char *from, const char 
   if (isdir (from))
     {
       error (0, 0, _("%s is a directory"), quote (from));
-      return 1;
+      return false;
     }
 
-  fail = copy (from, to, nonexistent_dst, x, &copy_into_self, NULL);
-
-  return fail;
+  return copy (from, to, false, x, &copy_into_self, NULL);
 }
 
 /* Set the attributes of file or directory PATH.
-   Return 0 if successful, 1 if not. */
+   Return true if successful.  */
 
-static int
+static bool
 change_attributes (const char *path)
 {
-  int err = 0;
+  bool ok = true;
 
   /* chown must precede chmod because on some systems,
      chown clears the set[ug]id bits for non-superusers,
@@ -530,22 +522,22 @@ change_attributes (const char *path)
       )
     {
       error (0, errno, _("cannot change ownership of %s"), quote (path));
-      err = 1;
+      ok = false;
     }
 
-  if (!err && chmod (path, mode))
+  if (ok && chmod (path, mode))
     {
       error (0, errno, _("cannot change permissions of %s"), quote (path));
-      err = 1;
+      ok = false;
     }
 
-  return err;
+  return ok;
 }
 
 /* Set the timestamps of file TO to match those of file FROM.
-   Return 0 if successful, 1 if not. */
+   Return true if successful.  */
 
-static int
+static bool
 change_timestamps (const char *from, const char *to)
 {
   struct stat stb;
@@ -554,7 +546,7 @@ change_timestamps (const char *from, con
   if (stat (from, &stb))
     {
       error (0, errno, _("cannot obtain time stamps for %s"), quote (from));
-      return 1;
+      return true;
     }
 
   timespec[0].tv_sec = stb.st_atime;
@@ -564,9 +556,9 @@ change_timestamps (const char *from, con
   if (utimens (to, timespec))
     {
       error (0, errno, _("cannot set time stamps for %s"), quote (to));
-      return 1;
+      return true;
     }
-  return 0;
+  return false;
 }
 
 /* Strip the symbol table from the file PATH.
Index: mv.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/mv.c,v
retrieving revision 1.159
diff -p -u -r1.159 mv.c
--- mv.c        4 Jul 2004 17:47:29 -0000       1.159
+++ mv.c        19 Jul 2004 03:52:02 -0000
@@ -57,7 +57,7 @@ enum
 char *program_name;
 
 /* Remove any trailing slashes from each SOURCE argument.  */
-static int remove_trailing_slashes;
+static bool remove_trailing_slashes;
 
 /* Valid arguments to the `--reply' option. */
 static char const* const reply_args[] =
@@ -92,17 +92,17 @@ static struct option const long_options[
 static void
 rm_option_init (struct rm_options *x)
 {
-  x->unlink_dirs = 0;
-  x->ignore_missing_files = 0;
+  x->unlink_dirs = false;
+  x->ignore_missing_files = false;
   x->root_dev_ino = NULL;
-  x->recursive = 1;
+  x->recursive = true;
 
   /* Should we prompt for removal, too?  No.  Prompting for the `move'
      part is enough.  It implies removal.  */
   x->interactive = 0;
-  x->stdin_tty = 0;
+  x->stdin_tty = false;
 
-  x->verbose = 0;
+  x->verbose = false;
 
   /* Since this program may well have to process additional command
      line arguments after any call to `rm', that function must preserve
@@ -114,24 +114,24 @@ rm_option_init (struct rm_options *x)
 static void
 cp_option_init (struct cp_options *x)
 {
-  x->copy_as_regular = 0;  /* FIXME: maybe make this an option */
+  x->copy_as_regular = false;  /* FIXME: maybe make this an option */
   x->dereference = DEREF_NEVER;
-  x->unlink_dest_before_opening = 0;
-  x->unlink_dest_after_failed_open = 0;
-  x->hard_link = 0;
+  x->unlink_dest_before_opening = false;
+  x->unlink_dest_after_failed_open = false;
+  x->hard_link = false;
   x->interactive = I_UNSPECIFIED;
-  x->move_mode = 1;
+  x->move_mode = true;
   x->myeuid = geteuid ();
-  x->one_file_system = 0;
-  x->preserve_ownership = 1;
-  x->preserve_links = 1;
-  x->preserve_mode = 1;
-  x->preserve_timestamps = 1;
-  x->require_preserve = 0;  /* FIXME: maybe make this an option */
-  x->recursive = 1;
+  x->one_file_system = false;
+  x->preserve_ownership = true;
+  x->preserve_links = true;
+  x->preserve_mode = true;
+  x->preserve_timestamps = true;
+  x->require_preserve = false;  /* FIXME: maybe make this an option */
+  x->recursive = true;
   x->sparse_mode = SPARSE_AUTO;  /* FIXME: maybe make this an option */
-  x->symbolic_link = 0;
-  x->set_mode = 0;
+  x->symbolic_link = false;
+  x->set_mode = false;
   x->mode = 0;
   x->stdin_tty = isatty (STDIN_FILENO);
 
@@ -141,8 +141,8 @@ cp_option_init (struct cp_options *x)
      have been allowed with the mask this process was started with.  */
   x->umask_kill = ~ umask (0);
 
-  x->update = 0;
-  x->verbose = 0;
+  x->update = false;
+  x->verbose = false;
   x->dest_info = NULL;
   x->src_info = NULL;
 }
@@ -170,18 +170,16 @@ target_directory_operand (char const *fi
 
 /* Move SOURCE onto DEST.  Handles cross-file-system moves.
    If SOURCE is a directory, DEST must not exist.
-   Return 0 if successful, 1 if an error occurred.  */
+   Return true if successful.  */
 
-static int
+static bool
 do_move (const char *source, const char *dest, const struct cp_options *x)
 {
-  int copy_into_self;
-  int rename_succeeded;
-  int fail;
-
-  fail = copy (source, dest, 0, x, &copy_into_self, &rename_succeeded);
+  bool copy_into_self;
+  bool rename_succeeded;
+  bool ok = copy (source, dest, false, x, &copy_into_self, &rename_succeeded);
 
-  if (!fail)
+  if (ok)
     {
       char const *dir_to_remove;
       if (copy_into_self)
@@ -198,7 +196,7 @@ do_move (const char *source, const char 
             and failing.  */
 
          dir_to_remove = NULL;
-         fail = 1;
+         ok = false;
        }
       else if (rename_succeeded)
        {
@@ -244,22 +242,22 @@ do_move (const char *source, const char 
          status = rm (1, &dir_to_remove, &rm_options);
          assert (VALID_STATUS (status));
          if (status == RM_ERROR)
-           fail = 1;
+           ok = false;
        }
     }
 
-  return fail;
+  return ok;
 }
 
 /* Move file SOURCE onto DEST.  Handles the case when DEST is a directory.
    Treat DEST as a directory if DEST_IS_DIR.
-   Return 0 if successful, non-zero if an error occurred.  */
+   Return true if successful.  */
 
-static int
+static bool
 movefile (char *source, char *dest, bool dest_is_dir,
          const struct cp_options *x)
 {
-  int fail;
+  bool ok;
 
   /* This code was introduced to handle the ambiguity in the semantics
      of mv that is induced by the varying semantics of the rename function.
@@ -278,15 +276,15 @@ movefile (char *source, char *dest, bool
       char const *src_basename = base_name (source);
       char *new_dest = path_concat (dest, src_basename, NULL);
       strip_trailing_slashes (new_dest);
-      fail = do_move (source, new_dest, x);
+      ok = do_move (source, new_dest, x);
       free (new_dest);
     }
   else
     {
-      fail = do_move (source, dest, x);
+      ok = do_move (source, dest, x);
     }
 
-  return fail;
+  return ok;
 }
 
 void
@@ -357,8 +355,8 @@ int
 main (int argc, char **argv)
 {
   int c;
-  int errors;
-  int make_backups = 0;
+  bool ok;
+  bool make_backups = false;
   char *backup_suffix_string;
   char *version_control_string = NULL;
   struct cp_options x;
@@ -381,8 +379,6 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  errors = 0;
-
   while ((c = getopt_long (argc, argv, "bfit:uvS:TV:", long_options, NULL))
         != -1)
     {
@@ -399,7 +395,7 @@ main (int argc, char **argv)
          /* Fall through.  */
 
        case 'b':
-         make_backups = 1;
+         make_backups = true;
          if (optarg)
            version_control_string = optarg;
          break;
@@ -414,7 +410,7 @@ main (int argc, char **argv)
                                     reply_args, reply_vals);
          break;
        case STRIP_TRAILING_SLASHES_OPTION:
-         remove_trailing_slashes = 1;
+         remove_trailing_slashes = true;
          break;
        case 't':
          if (target_directory)
@@ -434,13 +430,13 @@ main (int argc, char **argv)
          no_target_directory = true;
          break;
        case 'u':
-         x.update = 1;
+         x.update = true;
          break;
        case 'v':
-         x.verbose = 1;
+         x.verbose = true;
          break;
        case 'S':
-         make_backups = 1;
+         make_backups = true;
          backup_suffix_string = optarg;
          break;
        case_GETOPT_HELP_CHAR;
@@ -504,11 +500,12 @@ main (int argc, char **argv)
       if (2 <= n_files)
        dest_info_init (&x);
 
+      ok = true;
       for (i = 0; i < n_files; ++i)
-       errors |= movefile (file[i], target_directory, true, &x);
+       ok &= movefile (file[i], target_directory, true, &x);
     }
   else
-    errors = movefile (file[0], file[1], false, &x);
+    ok = movefile (file[0], file[1], false, &x);
 
-  exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
+  exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
Index: remove.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/remove.c,v
retrieving revision 1.114
diff -p -u -r1.114 remove.c
--- remove.c    28 Jul 2004 14:50:06 -0000      1.114
+++ remove.c    30 Jul 2004 05:55:01 -0000
@@ -209,7 +209,7 @@ push_dir (Dirstack_state *ds, const char
 static inline char *
 top_dir (Dirstack_state const *ds)
 {
-  int n_lengths = obstack_object_size (&ds->len_stack) / sizeof (size_t);
+  size_t n_lengths = obstack_object_size (&ds->len_stack) / sizeof (size_t);
   size_t *length = obstack_base (&ds->len_stack);
   size_t top_len = length[n_lengths - 1];
   char const *p = obstack_next_free (&ds->dir_stack) - top_len;
@@ -222,7 +222,7 @@ top_dir (Dirstack_state const *ds)
 static inline void
 pop_dir (Dirstack_state *ds)
 {
-  int n_lengths = obstack_object_size (&ds->len_stack) / sizeof (size_t);
+  size_t n_lengths = obstack_object_size (&ds->len_stack) / sizeof (size_t);
   size_t *length = obstack_base (&ds->len_stack);
   size_t top_len;
 
@@ -241,13 +241,13 @@ pop_dir (Dirstack_state *ds)
 
 /* Copy the SRC_LEN bytes of data beginning at SRC into the DST_LEN-byte
    buffer, DST, so that the last source byte is at the end of the destination
-   buffer.  If SRC_LEN is longer than DST_LEN, then set *TRUNCATED to non-zero.
+   buffer.  If SRC_LEN is longer than DST_LEN, then set *TRUNCATED.
    Set *RESULT to point to the beginning of (the portion of) the source data
    in DST.  Return the number of bytes remaining in the destination buffer.  */
 
 static size_t
 right_justify (char *dst, size_t dst_len, const char *src, size_t src_len,
-              char **result, int *truncated)
+              char **result, bool *truncated)
 {
   const char *sp;
   char *dp;
@@ -256,14 +256,14 @@ right_justify (char *dst, size_t dst_len
     {
       sp = src;
       dp = dst + (dst_len - src_len);
-      *truncated = 0;
+      *truncated = false;
     }
   else
     {
       sp = src + (src_len - dst_len);
       dp = dst;
       src_len = dst_len;
-      *truncated = 1;
+      *truncated = true;
     }
 
   *result = memcpy (dp, sp, src_len);
@@ -282,7 +282,7 @@ full_filename_ (Dirstack_state const *ds
   static char *buf = NULL;
   static size_t n_allocated = 0;
 
-  int dir_len = obstack_object_size (&ds->dir_stack);
+  size_t dir_len = obstack_object_size (&ds->dir_stack);
   char *dir_name = obstack_base (&ds->dir_stack);
   size_t n_bytes_needed;
   size_t filename_len;
@@ -305,7 +305,7 @@ full_filename_ (Dirstack_state const *ds
 #define SBUF_SIZE 512
 #define ELLIPSES_PREFIX "[...]"
          static char static_buf[SBUF_SIZE];
-         int truncated;
+         bool truncated;
          size_t len;
          char *p;
 
@@ -372,8 +372,8 @@ AD_stack_pop (Dirstack_state *ds)
    dev/ino numbers for `.' match the saved ones.
    Set *PREV_DIR to the name (in malloc'd storage) of the
    directory (usually now empty) from which we're coming.
-   Return nonzero upon failure of restore_cwd.  Otherwise, return 0. */
-static int
+   Return true if successful.  */
+static bool
 AD_pop_and_chdir (Dirstack_state *ds, char **prev_dir)
 {
   enum RM_status old_status = AD_stack_top(ds)->status;
@@ -417,11 +417,11 @@ AD_pop_and_chdir (Dirstack_state *ds, ch
       if (restore_cwd (&top->u.saved_cwd) != 0)
        {
          /* failed to return to initial working directory */
-         return 1;
+         return false;
        }
     }
 
-  return 0;
+  return true;
 }
 
 /* Initialize *HT if it is NULL.
@@ -510,7 +510,7 @@ AD_push (Dirstack_state *ds, char const 
   top->unremovable = NULL;
 }
 
-static int
+static bool
 AD_is_removable (Dirstack_state const *ds, char const *file)
 {
   struct AD_ent *top = AD_stack_top (ds);
@@ -573,14 +573,14 @@ prompt (Dirstack_state const *ds, char c
        struct rm_options const *x, enum Prompt_action mode,
        Ternary *is_dir, Ternary *is_empty)
 {
-  int write_protected = 0;
+  bool write_protected = false;
   struct stat *sbuf = NULL;
   struct stat buf;
 
   *is_empty = T_UNKNOWN;
   *is_dir = T_UNKNOWN;
 
-  if ((!x->ignore_missing_files && (x->interactive || x->stdin_tty)
+  if (((!x->ignore_missing_files & (x->interactive | x->stdin_tty))
        && (write_protected = write_protected_non_symlink (filename,
                                                          &sbuf, &buf)))
       || x->interactive)
@@ -609,7 +609,7 @@ prompt (Dirstack_state const *ds, char c
        {
          if ( ! x->interactive)
            return RM_OK;
-         write_protected = 0;
+         write_protected = false;
        }
 
       /* Issue the prompt.  */
@@ -1101,7 +1101,7 @@ remove_dir (Dirstack_state *ds, char con
           returned from, after nominally removing all of its contents.  */
        char *empty_dir;
 
-       if (AD_pop_and_chdir (ds, &empty_dir) != 0)
+       if (! AD_pop_and_chdir (ds, &empty_dir))
          (*cwd_state)->saved_errno = errno;
 
        /* Note: the above may have failed due to restore_cwd failure.
Index: rm.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/rm.c,v
retrieving revision 1.129
diff -p -u -r1.129 rm.c
--- rm.c        21 Jun 2004 15:03:35 -0000      1.129
+++ rm.c        19 Jul 2004 03:53:49 -0000
@@ -145,13 +145,13 @@ truly unrecoverable, consider using shre
 static void
 rm_option_init (struct rm_options *x)
 {
-  x->unlink_dirs = 0;
-  x->ignore_missing_files = 0;
-  x->interactive = 0;
-  x->recursive = 0;
+  x->unlink_dirs = false;
+  x->ignore_missing_files = false;
+  x->interactive = false;
+  x->recursive = false;
   x->root_dev_ino = NULL;
   x->stdin_tty = isatty (STDIN_FILENO);
-  x->verbose = 0;
+  x->verbose = false;
 
   /* Since this program exits immediately after calling `rm', rm need not
      expend unnecessary effort to preserve the initial working directory.  */
@@ -163,7 +163,6 @@ main (int argc, char **argv)
 {
   bool preserve_root = false;
   struct rm_options x;
-  int fail = 0;
   int c;
 
   initialize_main (&argc, &argv);
@@ -184,22 +183,22 @@ main (int argc, char **argv)
          break;
 
        case 'd':
-         x.unlink_dirs = 1;
+         x.unlink_dirs = true;
          break;
 
        case 'f':
-         x.interactive = 0;
-         x.ignore_missing_files = 1;
+         x.interactive = false;
+         x.ignore_missing_files = true;
          break;
 
        case 'i':
-         x.interactive = 1;
-         x.ignore_missing_files = 0;
+         x.interactive = true;
+         x.ignore_missing_files = false;
          break;
 
        case 'r':
        case 'R':
-         x.recursive = 1;
+         x.recursive = true;
          break;
 
        case NO_PRESERVE_ROOT:
@@ -211,11 +210,11 @@ main (int argc, char **argv)
          break;
 
        case PRESUME_INPUT_TTY_OPTION:
-         x.stdin_tty = 1;
+         x.stdin_tty = true;
          break;
 
        case 'v':
-         x.verbose = 1;
+         x.verbose = true;
          break;
 
        case_GETOPT_HELP_CHAR;
@@ -236,7 +235,7 @@ main (int argc, char **argv)
        }
     }
 
-  if (x.recursive && preserve_root)
+  if (x.recursive & preserve_root)
     {
       static struct dev_ino dev_ino_buf;
       x.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
@@ -251,9 +250,6 @@ main (int argc, char **argv)
 
     enum RM_status status = rm (n_files, file, &x);
     assert (VALID_STATUS (status));
-    if (status == RM_ERROR)
-      fail = 1;
+    exit (status == RM_ERROR ? EXIT_FAILURE : EXIT_SUCCESS);
   }
-
-  exit (fail);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]