aboutsummaryrefslogtreecommitdiff
path: root/coreutils/mv.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-02-21 07:49:54 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-02-21 07:49:54 +0000
commit96099d51b6a872fbd33cdaef123bf93fbc4e9871 (patch)
tree10e414f256d90f899309d851bd2eacea069ea236 /coreutils/mv.c
parentced9705c42d720ce49b99e3c7738969e5fdf63bf (diff)
downloadbusybox-w32-96099d51b6a872fbd33cdaef123bf93fbc4e9871.tar.gz
busybox-w32-96099d51b6a872fbd33cdaef123bf93fbc4e9871.tar.bz2
busybox-w32-96099d51b6a872fbd33cdaef123bf93fbc4e9871.zip
Use return instead of exit, use == instead of & ==, left justify labels,
adjustment of whitespace.
Diffstat (limited to 'coreutils/mv.c')
-rw-r--r--coreutils/mv.c62
1 files changed, 29 insertions, 33 deletions
diff --git a/coreutils/mv.c b/coreutils/mv.c
index 55da2cc68..c28d0500e 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -41,7 +41,6 @@ static const struct option mv_long_options[] = {
41 { 0, 0, 0, 0 } 41 { 0, 0, 0, 0 }
42}; 42};
43 43
44static const char mv_getopt_short_option[] = "fi";
45#define OPT_FILEUTILS_FORCE 1 44#define OPT_FILEUTILS_FORCE 1
46#define OPT_FILEUTILS_INTERACTIVE 2 45#define OPT_FILEUTILS_INTERACTIVE 2
47 46
@@ -49,21 +48,19 @@ static const char fmt[] = "cannot overwrite %sdirectory with %sdirectory";
49 48
50extern int mv_main(int argc, char **argv) 49extern int mv_main(int argc, char **argv)
51{ 50{
52 struct stat source_stat;
53 struct stat dest_stat; 51 struct stat dest_stat;
54 const char *last; 52 const char *last;
55 const char *dest; 53 const char *dest;
56 int dest_exists;
57 int source_exists;
58 unsigned long flags; 54 unsigned long flags;
55 int dest_exists;
59 int status = 0; 56 int status = 0;
60 57
61 bb_applet_long_options = mv_long_options; 58 bb_applet_long_options = mv_long_options;
62 bb_opt_complementaly = "f-i:i-f"; 59 bb_opt_complementaly = "f-i:i-f";
63 flags = bb_getopt_ulflags(argc, argv, mv_getopt_short_option); 60 flags = bb_getopt_ulflags(argc, argv, "fi");
64 61 if (optind + 2 > argc) {
65 if (optind + 2 > argc)
66 bb_show_usage(); 62 bb_show_usage();
63 }
67 64
68 last = argv[argc - 1]; 65 last = argv[argc - 1];
69 argv += optind; 66 argv += optind;
@@ -86,30 +83,34 @@ extern int mv_main(int argc, char **argv)
86 goto RET_1; 83 goto RET_1;
87 } 84 }
88 85
89 DO_MOVE: 86DO_MOVE:
90 87
91 if (dest_exists && !(flags & OPT_FILEUTILS_FORCE) && 88 if (dest_exists && !(flags & OPT_FILEUTILS_FORCE) &&
92 ((access(dest, W_OK) < 0 && isatty(0)) || 89 ((access(dest, W_OK) < 0 && isatty(0)) ||
93 (flags & OPT_FILEUTILS_INTERACTIVE))) { 90 (flags & OPT_FILEUTILS_INTERACTIVE))) {
94 if (fprintf(stderr, "mv: overwrite `%s'? ", dest) < 0) { 91 if (fprintf(stderr, "mv: overwrite `%s'? ", dest) < 0) {
95 goto RET_1; /* Ouch! fprintf failed! */ 92 goto RET_1; /* Ouch! fprintf failed! */
96 } 93 }
97 if (!bb_ask_confirmation()) 94 if (!bb_ask_confirmation()) {
98 goto RET_0; 95 goto RET_0;
99 } 96 }
100 97 }
101 if (rename(*argv, dest) < 0) { 98 if (rename(*argv, dest) < 0) {
99 struct stat source_stat;
100 int source_exists;
101
102 if (errno != EXDEV) { 102 if (errno != EXDEV) {
103 bb_perror_msg("unable to rename `%s'", *argv); 103 bb_perror_msg("unable to rename `%s'", *argv);
104 } else if ((source_exists = cp_mv_stat(*argv, &source_stat)) >= 0) { 104 }
105 else if ((source_exists = cp_mv_stat(*argv, &source_stat)) >= 0) {
105 if (dest_exists) { 106 if (dest_exists) {
106 if (dest_exists & 2) { 107 if (dest_exists == 3) {
107 if (!(source_exists & 2)) { 108 if (source_exists != 3) {
108 bb_error_msg(fmt, "", "non-"); 109 bb_error_msg(fmt, "", "non-");
109 goto RET_1; 110 goto RET_1;
110 } 111 }
111 } else { 112 } else {
112 if (source_exists & 2) { 113 if (source_exists == 3) {
113 bb_error_msg(fmt, "non-", ""); 114 bb_error_msg(fmt, "non-", "");
114 goto RET_1; 115 goto RET_1;
115 } 116 }
@@ -118,26 +119,21 @@ extern int mv_main(int argc, char **argv)
118 bb_perror_msg("cannot remove `%s'", dest); 119 bb_perror_msg("cannot remove `%s'", dest);
119 goto RET_1; 120 goto RET_1;
120 } 121 }
121 } 122 }
122
123 if ((copy_file(*argv, dest, 123 if ((copy_file(*argv, dest,
124 FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) 124 FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) &&
125 && (remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0) 125 (remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)) {
126 ) {
127 goto RET_0; 126 goto RET_0;
128 } 127 }
129
130 } 128 }
131 RET_1: 129RET_1:
132 status = 1; 130 status = 1;
133 } 131 }
134 132RET_0:
135 RET_0:
136 if (dest != last) { 133 if (dest != last) {
137 free((void *) dest); 134 free((void *) dest);
138 } 135 }
139
140 } while (*++argv != last); 136 } while (*++argv != last);
141 137
142 exit(status); 138 return (status);
143} 139}