Include stat-time.h, and use its functions instead of the obsolete
[platform/upstream/coreutils.git] / src / cp.c
index b38032a..4e08612 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -33,6 +33,7 @@
 #include "filenamecat.h"
 #include "quote.h"
 #include "quotearg.h"
+#include "stat-time.h"
 #include "utimens.h"
 
 #define ASSIGN_BASENAME_STRDUPA(Dest, File_name)       \
@@ -94,23 +95,23 @@ static char const *const sparse_type_string[] =
 {
   "never", "auto", "always", NULL
 };
-
 static enum Sparse_type const sparse_type[] =
 {
   SPARSE_NEVER, SPARSE_AUTO, SPARSE_ALWAYS
 };
+ARGMATCH_VERIFY (sparse_type_string, sparse_type);
 
 /* Valid arguments to the `--reply' option. */
 static char const* const reply_args[] =
 {
   "yes", "no", "query", NULL
 };
-
 /* The values that correspond to the above strings. */
 static int const reply_vals[] =
 {
   I_ALWAYS_YES, I_ALWAYS_NO, I_ASK_USER
 };
+ARGMATCH_VERIFY (reply_args, reply_vals);
 
 static struct option const long_opts[] =
 {
@@ -130,7 +131,8 @@ static struct option const long_opts[] =
   {"preserve", optional_argument, NULL, PRESERVE_ATTRIBUTES_OPTION},
   {"recursive", no_argument, NULL, 'R'},
   {"remove-destination", no_argument, NULL, UNLINK_DEST_BEFORE_OPENING},
-  {"reply", required_argument, NULL, REPLY_OPTION},
+  {"reply", required_argument, NULL, REPLY_OPTION}, /* Deprecated 2005-07-03,
+                                                      remove in 2008. */
   {"sparse", required_argument, NULL, SPARSE_OPTION},
   {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
   {"suffix", required_argument, NULL, 'S'},
@@ -138,7 +140,6 @@ static struct option const long_opts[] =
   {"target-directory", required_argument, NULL, 't'},
   {"update", no_argument, NULL, 'u'},
   {"verbose", no_argument, NULL, 'v'},
-  {"version-control", required_argument, NULL, 'V'}, /* Deprecated. FIXME. */
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -201,8 +202,6 @@ Mandatory arguments to long options are mandatory for short options too.\n\
                                  attempting to open it (contrast with --force)\n\
 "), stdout);
       fputs (_("\
-      --reply={yes,no,query}   specify how to handle the prompt about an\n\
-                                 existing destination file\n\
       --sparse=WHEN            control creation of sparse files\n\
       --strip-trailing-slashes remove any trailing slashes from each SOURCE\n\
                                  argument\n\
@@ -306,10 +305,8 @@ re_protect (char const *const_dst_name, size_t src_offset,
        {
          struct timespec timespec[2];
 
-         timespec[0].tv_sec = src_sb.st_atime;
-         timespec[0].tv_nsec = TIMESPEC_NS (src_sb.st_atim);
-         timespec[1].tv_sec = src_sb.st_mtime;
-         timespec[1].tv_nsec = TIMESPEC_NS (src_sb.st_mtim);
+         timespec[0] = get_stat_atime (&src_sb);
+         timespec[1] = get_stat_mtime (&src_sb);
 
          if (utimens (dst_name, timespec))
            {
@@ -730,13 +727,13 @@ decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
       PRESERVE_MODE, PRESERVE_TIMESTAMPS,
       PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_ALL
     };
-
   /* Valid arguments to the `--preserve' option. */
   static char const* const preserve_args[] =
     {
       "mode", "timestamps",
       "ownership", "links", "all", NULL
     };
+  ARGMATCH_VERIFY (preserve_args, preserve_vals);
 
   char *arg_writable = xstrdup (arg);
   char *s = arg_writable;
@@ -814,7 +811,7 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  while ((c = getopt_long (argc, argv, "abdfHilLprst:uvxPRS:TV:",
+  while ((c = getopt_long (argc, argv, "abdfHilLprst:uvxPRS:T",
                           long_opts, NULL))
         != -1)
     {
@@ -835,13 +832,6 @@ main (int argc, char **argv)
          x.recursive = true;
          break;
 
-       case 'V':  /* FIXME: this is deprecated.  Remove it in 2001.  */
-         error (0, 0,
-                _("warning: --version-control (-V) is obsolete;  support for\
- it\nwill be removed in some future release.  Use --backup=%s instead."
-                  ), optarg);
-         /* Fall through.  */
-
        case 'b':
          make_backups = true;
          if (optarg)
@@ -913,9 +903,11 @@ main (int argc, char **argv)
          x.recursive = true;
          break;
 
-       case REPLY_OPTION:
+       case REPLY_OPTION: /* Deprecated */
          x.interactive = XARGMATCH ("--reply", optarg,
                                     reply_args, reply_vals);
+         error (0, 0,
+                _("the --reply option is deprecated; use -i or -f instead"));
          break;
 
        case UNLINK_DEST_BEFORE_OPENING: