Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/cp.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/cp.c
r821 r1770 4 4 * 5 5 * Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu> 6 * SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp> 6 7 * 7 8 * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. 8 9 */ 9 10 10 /* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */11 /* BB_AUDIT GNU defects - only extension options supported are -a and -d. */12 11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */ 13 12 … … 17 16 */ 18 17 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" 29 19 #include "libcoreutils/coreutils.h" 30 20 21 /* This is a NOEXEC applet. Be very careful! */ 22 23 24 int cp_main(int argc, char **argv); 31 25 int cp_main(int argc, char **argv) 32 26 { … … 39 33 int flags; 40 34 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 }; 41 42 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"); 59 49 /* Default behavior of cp is to dereference, so we don't have to do 60 50 * anything special when we are given -L. 61 51 * The behavior of -H is *almost* like -L, but not quite, so let's 62 52 * 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(); 65 60 } 66 */ 61 #endif 67 62 68 63 flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */ … … 78 73 if (optind + 2 == argc) { 79 74 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 84 82 /* ...if neither is a directory or... */ 85 83 if ( !((s_flags | d_flags) & 2) || 86 84 /* ...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) 90 86 ) { 91 87 /* ...do a simple copy. */ 92 dest = last;88 dest = xstrdup(last); 93 89 goto DO_COPY; /* Note: optind+2==argc implies argv[1]==last below. */ 94 90 } … … 97 93 do { 98 94 dest = concat_path_file(last, bb_get_last_path_component(*argv)); 99 95 DO_COPY: 100 96 if (copy_file(*argv, dest, flags) < 0) { 101 97 status = 1; 102 98 } 103 if (*++argv == last) { 104 break; 105 } 106 free((void *) dest); 107 } while (1); 99 free((void*)dest); 100 } while (*++argv != last); 108 101 109 exit(status);102 return status; 110 103 }
Note:
See TracChangeset
for help on using the changeset viewer.