Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/coreutils/ln.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/coreutils/ln.c
r2725 r3232 12 12 /* http://www.opengroup.org/onlinepubs/007904975/utilities/ln.html */ 13 13 14 //usage:#define ln_trivial_usage 15 //usage: "[OPTIONS] TARGET... LINK|DIR" 16 //usage:#define ln_full_usage "\n\n" 17 //usage: "Create a link LINK or DIR/TARGET to the specified TARGET(s)\n" 18 //usage: "\n -s Make symlinks instead of hardlinks" 19 //usage: "\n -f Remove existing destinations" 20 //usage: "\n -n Don't dereference symlinks - treat like normal file" 21 //usage: "\n -b Make a backup of the target (if exists) before link operation" 22 //usage: "\n -S suf Use suffix instead of ~ when making backup files" 23 //usage: "\n -T 2nd arg must be a DIR" 24 //usage: "\n -v Verbose" 25 //usage: 26 //usage:#define ln_example_usage 27 //usage: "$ ln -s BusyBox /tmp/ls\n" 28 //usage: "$ ls -l /tmp/ls\n" 29 //usage: "lrwxrwxrwx 1 root root 7 Apr 12 18:39 ls -> BusyBox*\n" 30 14 31 #include "libbb.h" 15 32 … … 17 34 18 35 19 #define LN_SYMLINK 1 20 #define LN_FORCE 2 21 #define LN_NODEREFERENCE 4 22 #define LN_BACKUP 8 23 #define LN_SUFFIX 16 36 #define LN_SYMLINK (1 << 0) 37 #define LN_FORCE (1 << 1) 38 #define LN_NODEREFERENCE (1 << 2) 39 #define LN_BACKUP (1 << 3) 40 #define LN_SUFFIX (1 << 4) 41 #define LN_VERBOSE (1 << 5) 42 #define LN_LINKFILE (1 << 6) 24 43 25 44 int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 36 55 37 56 opt_complementary = "-1"; /* min one arg */ 38 opts = getopt32(argv, "sfnbS: ", &suffix);57 opts = getopt32(argv, "sfnbS:vT", &suffix); 39 58 40 59 last = argv[argc - 1]; 41 60 argv += optind; 61 argc -= optind; 42 62 43 if (argc == optind + 1) { 63 if ((opts & LN_LINKFILE) && argc > 2) { 64 bb_error_msg_and_die("-T accepts 2 args max"); 65 } 66 67 if (!argv[1]) { 68 /* "ln PATH/TO/FILE" -> "ln PATH/TO/FILE FILE" */ 44 69 *--argv = last; 70 /* xstrdup is needed: "ln -s PATH/TO/FILE/" is equivalent to 71 * "ln -s PATH/TO/FILE/ FILE", not "ln -s PATH/TO/FILE FILE" 72 */ 45 73 last = bb_get_last_path_component_strip(xstrdup(last)); 46 74 } … … 51 79 52 80 if (is_directory(src, 53 (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE ,54 NULL)81 (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE 82 ) 55 83 ) { 84 if (opts & LN_LINKFILE) { 85 bb_error_msg_and_die("'%s' is a directory", src); 86 } 56 87 src_name = xstrdup(*argv); 57 88 src = concat_path_file(src, bb_get_last_path_component_strip(src_name)); … … 94 125 } 95 126 127 if (opts & LN_VERBOSE) { 128 printf("'%s' -> '%s'\n", src, *argv); 129 } 130 96 131 if (link_func(*argv, src) != 0) { 97 132 bb_simple_perror_msg(src);
Note:
See TracChangeset
for help on using the changeset viewer.