Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/coreutils/cp.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/coreutils/cp.c

    r821 r1765  
    44 *
    55 * Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
     6 * SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
    67 *
    78 * Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
    89 */
    910
    10 /* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
    11 /* BB_AUDIT GNU defects - only extension options supported are -a and -d.  */
    1211/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
    1312
     
    1716 */
    1817
    19 #include <sys/types.h>
    20 #include <sys/stat.h>
    21 #include <unistd.h>
    22 #include <fcntl.h>
    23 #include <utime.h>
    24 #include <errno.h>
    25 #include <dirent.h>
    26 #include <stdlib.h>
    27 #include <assert.h>
    28 #include "busybox.h"
     18#include "libbb.h"
    2919#include "libcoreutils/coreutils.h"
    3020
     21/* This is a NOEXEC applet. Be very careful! */
     22
     23
     24int cp_main(int argc, char **argv);
    3125int cp_main(int argc, char **argv)
    3226{
     
    3933    int flags;
    4034    int status = 0;
     35    enum {
     36        OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
     37        OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
     38        OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
     39        OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
     40        OPT_L = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
     41    };
    4142
    42     flags = bb_getopt_ulflags(argc, argv, "pdRfiarPHL");
    43 
    44     if (flags & 32) {
    45         flags |= (FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR | FILEUTILS_DEREFERENCE);
    46     }
    47     if (flags & 64) {
    48         /* Make -r a synonym for -R,
    49          * -r was marked as obsolete in SUSv3, but is included for compatibility
    50          */
    51         flags |= FILEUTILS_RECUR;
    52     }
    53     if (flags & 128) {
    54         /* Make -P a synonym for -d,
    55          * -d is the GNU option while -P is the POSIX 2003 option
    56          */
    57         flags |= FILEUTILS_DEREFERENCE;
    58     }
     43    // Soft- and hardlinking don't mix
     44    // -P and -d are the same (-P is POSIX, -d is GNU)
     45    // -r and -R are the same
     46    // -a = -pdR
     47    opt_complementary = "l--s:s--l:Pd:rR:apdR";
     48    flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHL");
    5949    /* Default behavior of cp is to dereference, so we don't have to do
    6050     * anything special when we are given -L.
    6151     * The behavior of -H is *almost* like -L, but not quite, so let's
    6252     * just ignore it too for fun.
    63     if (flags & 256 || flags & 512) {
    64         ;
     53    if (flags & OPT_L) ...
     54    if (flags & OPT_H) ... // deref command-line params only
     55    */
     56
     57#if ENABLE_SELINUX
     58    if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {
     59        selinux_or_die();
    6560    }
    66     */
     61#endif
    6762
    6863    flags ^= FILEUTILS_DEREFERENCE;     /* The sense of this flag was reversed. */
     
    7873    if (optind + 2 == argc) {
    7974        s_flags = cp_mv_stat2(*argv, &source_stat,
    80                               (flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
    81         if ((s_flags < 0) || ((d_flags = cp_mv_stat(last, &dest_stat)) < 0)) {
    82             exit(EXIT_FAILURE);
    83         }
     75                      (flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
     76        if (s_flags < 0)
     77            return EXIT_FAILURE;
     78        d_flags = cp_mv_stat(last, &dest_stat);
     79        if (d_flags < 0)
     80            return EXIT_FAILURE;
     81
    8482        /* ...if neither is a directory or...  */
    8583        if ( !((s_flags | d_flags) & 2) ||
    8684            /* ...recursing, the 1st is a directory, and the 2nd doesn't exist... */
    87             /* ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) */
    88             /* Simplify the above since FILEUTILS_RECUR >> 1 == 2. */
    89             ((((flags & FILEUTILS_RECUR) >> 1) & s_flags) && !d_flags)
     85            ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
    9086        ) {
    9187            /* ...do a simple copy.  */
    92             dest = last;
     88            dest = xstrdup(last);
    9389            goto DO_COPY; /* Note: optind+2==argc implies argv[1]==last below. */
    9490        }
     
    9793    do {
    9894        dest = concat_path_file(last, bb_get_last_path_component(*argv));
    99     DO_COPY:
     95 DO_COPY:
    10096        if (copy_file(*argv, dest, flags) < 0) {
    10197            status = 1;
    10298        }
    103         if (*++argv == last) {
    104             break;
    105         }
    106         free((void *) dest);
    107     } while (1);
     99        free((void*)dest);
     100    } while (*++argv != last);
    108101
    109     exit(status);
     102    return status;
    110103}
Note: See TracChangeset for help on using the changeset viewer.