diff options
-rw-r--r-- | coreutils/cp.c | 18 | ||||
-rw-r--r-- | coreutils/mv.c | 18 | ||||
-rw-r--r-- | cp.c | 18 | ||||
-rw-r--r-- | include/libbb.h | 10 | ||||
-rw-r--r-- | libbb/copy_file.c | 19 | ||||
-rw-r--r-- | libbb/libbb.h | 10 | ||||
-rw-r--r-- | mv.c | 18 |
7 files changed, 56 insertions, 55 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c index 254445f02..82d43adff 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -42,22 +42,22 @@ extern int cp_main(int argc, char **argv) | |||
42 | while ((opt = getopt(argc, argv, "adfipR")) != -1) | 42 | while ((opt = getopt(argc, argv, "adfipR")) != -1) |
43 | switch (opt) { | 43 | switch (opt) { |
44 | case 'a': | 44 | case 'a': |
45 | flags |= CP_PRESERVE_STATUS | CP_RECUR; | 45 | flags |= FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR; |
46 | /* fallthrough */ | 46 | /* fallthrough */ |
47 | case 'd': | 47 | case 'd': |
48 | flags |= CP_PRESERVE_SYMLINKS; | 48 | flags |= FILEUTILS_PRESERVE_SYMLINKS; |
49 | break; | 49 | break; |
50 | case 'f': | 50 | case 'f': |
51 | flags |= CP_FORCE; | 51 | flags |= FILEUTILS_FORCE; |
52 | break; | 52 | break; |
53 | case 'i': | 53 | case 'i': |
54 | flags |= CP_INTERACTIVE; | 54 | flags |= FILEUTILS_INTERACTIVE; |
55 | break; | 55 | break; |
56 | case 'p': | 56 | case 'p': |
57 | flags |= CP_PRESERVE_STATUS; | 57 | flags |= FILEUTILS_PRESERVE_STATUS; |
58 | break; | 58 | break; |
59 | case 'R': | 59 | case 'R': |
60 | flags |= CP_RECUR; | 60 | flags |= FILEUTILS_RECUR; |
61 | break; | 61 | break; |
62 | default: | 62 | default: |
63 | show_usage(); | 63 | show_usage(); |
@@ -73,9 +73,9 @@ extern int cp_main(int argc, char **argv) | |||
73 | int source_exists = 1; | 73 | int source_exists = 1; |
74 | int dest_exists = 1; | 74 | int dest_exists = 1; |
75 | 75 | ||
76 | if (((flags & CP_PRESERVE_SYMLINKS) && | 76 | if (((flags & FILEUTILS_PRESERVE_SYMLINKS) && |
77 | lstat(argv[optind], &source_stat) < 0) || | 77 | lstat(argv[optind], &source_stat) < 0) || |
78 | (!(flags & CP_PRESERVE_SYMLINKS) && | 78 | (!(flags & FILEUTILS_PRESERVE_SYMLINKS) && |
79 | stat(argv[optind], &source_stat))) { | 79 | stat(argv[optind], &source_stat))) { |
80 | if (errno != ENOENT) | 80 | if (errno != ENOENT) |
81 | perror_msg_and_die("unable to stat `%s'", argv[optind]); | 81 | perror_msg_and_die("unable to stat `%s'", argv[optind]); |
@@ -93,7 +93,7 @@ extern int cp_main(int argc, char **argv) | |||
93 | (!dest_exists || !S_ISDIR(dest_stat.st_mode))) || | 93 | (!dest_exists || !S_ISDIR(dest_stat.st_mode))) || |
94 | /* ...recursing, the first is a directory, and the | 94 | /* ...recursing, the first is a directory, and the |
95 | * second doesn't exist, then... */ | 95 | * second doesn't exist, then... */ |
96 | ((flags & CP_RECUR) && S_ISDIR(source_stat.st_mode) && | 96 | ((flags & FILEUTILS_RECUR) && S_ISDIR(source_stat.st_mode) && |
97 | !dest_exists)) { | 97 | !dest_exists)) { |
98 | /* ...do a simple copy. */ | 98 | /* ...do a simple copy. */ |
99 | if (copy_file(argv[optind], argv[optind + 1], flags) < 0) | 99 | if (copy_file(argv[optind], argv[optind + 1], flags) < 0) |
diff --git a/coreutils/mv.c b/coreutils/mv.c index 13d1aae5b..efc4ae6d8 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c | |||
@@ -30,7 +30,7 @@ | |||
30 | 30 | ||
31 | #include "busybox.h" | 31 | #include "busybox.h" |
32 | 32 | ||
33 | static int flags = CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS; | 33 | static int flags; |
34 | 34 | ||
35 | static int remove_file(const char *path, struct stat *statbuf, void *junk) | 35 | static int remove_file(const char *path, struct stat *statbuf, void *junk) |
36 | { | 36 | { |
@@ -88,8 +88,8 @@ static int manual_rename(const char *source, const char *dest) | |||
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | if (copy_file(source, dest, | 91 | if (copy_file(source, dest, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS | |
92 | CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS) < 0) | 92 | FILEUTILS_PRESERVE_SYMLINKS) < 0) |
93 | return -1; | 93 | return -1; |
94 | 94 | ||
95 | if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file, | 95 | if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file, |
@@ -112,9 +112,9 @@ static int move_file(const char *source, const char *dest) | |||
112 | dest_exists = 0; | 112 | dest_exists = 0; |
113 | } | 113 | } |
114 | 114 | ||
115 | if (dest_exists && !(flags & CP_FORCE) && | 115 | if (dest_exists && !(flags & FILEUTILS_FORCE) && |
116 | ((access(dest, W_OK) < 0 && isatty(0)) || | 116 | ((access(dest, W_OK) < 0 && isatty(0)) || |
117 | (flags & CP_INTERACTIVE))) { | 117 | (flags & FILEUTILS_INTERACTIVE))) { |
118 | fprintf(stderr, "mv: overwrite `%s'? ", dest); | 118 | fprintf(stderr, "mv: overwrite `%s'? ", dest); |
119 | if (!ask_confirmation()) | 119 | if (!ask_confirmation()) |
120 | return 0; | 120 | return 0; |
@@ -140,12 +140,12 @@ extern int mv_main(int argc, char **argv) | |||
140 | while ((opt = getopt(argc, argv, "fi")) != -1) | 140 | while ((opt = getopt(argc, argv, "fi")) != -1) |
141 | switch (opt) { | 141 | switch (opt) { |
142 | case 'f': | 142 | case 'f': |
143 | flags &= ~CP_INTERACTIVE; | 143 | flags &= ~FILEUTILS_INTERACTIVE; |
144 | flags |= CP_FORCE; | 144 | flags |= FILEUTILS_FORCE; |
145 | break; | 145 | break; |
146 | case 'i': | 146 | case 'i': |
147 | flags &= ~CP_FORCE; | 147 | flags &= ~FILEUTILS_FORCE; |
148 | flags |= CP_INTERACTIVE; | 148 | flags |= FILEUTILS_INTERACTIVE; |
149 | break; | 149 | break; |
150 | default: | 150 | default: |
151 | show_usage(); | 151 | show_usage(); |
@@ -42,22 +42,22 @@ extern int cp_main(int argc, char **argv) | |||
42 | while ((opt = getopt(argc, argv, "adfipR")) != -1) | 42 | while ((opt = getopt(argc, argv, "adfipR")) != -1) |
43 | switch (opt) { | 43 | switch (opt) { |
44 | case 'a': | 44 | case 'a': |
45 | flags |= CP_PRESERVE_STATUS | CP_RECUR; | 45 | flags |= FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR; |
46 | /* fallthrough */ | 46 | /* fallthrough */ |
47 | case 'd': | 47 | case 'd': |
48 | flags |= CP_PRESERVE_SYMLINKS; | 48 | flags |= FILEUTILS_PRESERVE_SYMLINKS; |
49 | break; | 49 | break; |
50 | case 'f': | 50 | case 'f': |
51 | flags |= CP_FORCE; | 51 | flags |= FILEUTILS_FORCE; |
52 | break; | 52 | break; |
53 | case 'i': | 53 | case 'i': |
54 | flags |= CP_INTERACTIVE; | 54 | flags |= FILEUTILS_INTERACTIVE; |
55 | break; | 55 | break; |
56 | case 'p': | 56 | case 'p': |
57 | flags |= CP_PRESERVE_STATUS; | 57 | flags |= FILEUTILS_PRESERVE_STATUS; |
58 | break; | 58 | break; |
59 | case 'R': | 59 | case 'R': |
60 | flags |= CP_RECUR; | 60 | flags |= FILEUTILS_RECUR; |
61 | break; | 61 | break; |
62 | default: | 62 | default: |
63 | show_usage(); | 63 | show_usage(); |
@@ -73,9 +73,9 @@ extern int cp_main(int argc, char **argv) | |||
73 | int source_exists = 1; | 73 | int source_exists = 1; |
74 | int dest_exists = 1; | 74 | int dest_exists = 1; |
75 | 75 | ||
76 | if (((flags & CP_PRESERVE_SYMLINKS) && | 76 | if (((flags & FILEUTILS_PRESERVE_SYMLINKS) && |
77 | lstat(argv[optind], &source_stat) < 0) || | 77 | lstat(argv[optind], &source_stat) < 0) || |
78 | (!(flags & CP_PRESERVE_SYMLINKS) && | 78 | (!(flags & FILEUTILS_PRESERVE_SYMLINKS) && |
79 | stat(argv[optind], &source_stat))) { | 79 | stat(argv[optind], &source_stat))) { |
80 | if (errno != ENOENT) | 80 | if (errno != ENOENT) |
81 | perror_msg_and_die("unable to stat `%s'", argv[optind]); | 81 | perror_msg_and_die("unable to stat `%s'", argv[optind]); |
@@ -93,7 +93,7 @@ extern int cp_main(int argc, char **argv) | |||
93 | (!dest_exists || !S_ISDIR(dest_stat.st_mode))) || | 93 | (!dest_exists || !S_ISDIR(dest_stat.st_mode))) || |
94 | /* ...recursing, the first is a directory, and the | 94 | /* ...recursing, the first is a directory, and the |
95 | * second doesn't exist, then... */ | 95 | * second doesn't exist, then... */ |
96 | ((flags & CP_RECUR) && S_ISDIR(source_stat.st_mode) && | 96 | ((flags & FILEUTILS_RECUR) && S_ISDIR(source_stat.st_mode) && |
97 | !dest_exists)) { | 97 | !dest_exists)) { |
98 | /* ...do a simple copy. */ | 98 | /* ...do a simple copy. */ |
99 | if (copy_file(argv[optind], argv[optind + 1], flags) < 0) | 99 | if (copy_file(argv[optind], argv[optind + 1], flags) < 0) |
diff --git a/include/libbb.h b/include/libbb.h index 4eeb99343..404d7076c 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -255,11 +255,11 @@ extern int gz_open(FILE *compressed_file, int *pid); | |||
255 | /* extern int convert(char *fn, int ConvType); */ | 255 | /* extern int convert(char *fn, int ConvType); */ |
256 | 256 | ||
257 | enum { | 257 | enum { |
258 | CP_PRESERVE_STATUS = 1, | 258 | FILEUTILS_PRESERVE_STATUS = 1, |
259 | CP_PRESERVE_SYMLINKS = 2, | 259 | FILEUTILS_PRESERVE_SYMLINKS = 2, |
260 | CP_RECUR = 4, | 260 | FILEUTILS_RECUR = 4, |
261 | CP_FORCE = 8, | 261 | FILEUTILS_FORCE = 8, |
262 | CP_INTERACTIVE = 16 | 262 | FILEUTILS_INTERACTIVE = 16 |
263 | }; | 263 | }; |
264 | 264 | ||
265 | extern const char *applet_name; | 265 | extern const char *applet_name; |
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index f24d1b119..4ee3efdbc 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -39,8 +39,9 @@ int copy_file(const char *source, const char *dest, int flags) | |||
39 | int dest_exists = 1; | 39 | int dest_exists = 1; |
40 | int status = 0; | 40 | int status = 0; |
41 | 41 | ||
42 | if (((flags & CP_PRESERVE_SYMLINKS) && lstat(source, &source_stat) < 0) || | 42 | if (((flags & FILEUTILS_PRESERVE_SYMLINKS) && |
43 | (!(flags & CP_PRESERVE_SYMLINKS) && | 43 | lstat(source, &source_stat) < 0) || |
44 | (!(flags & FILEUTILS_PRESERVE_SYMLINKS) && | ||
44 | stat(source, &source_stat) < 0)) { | 45 | stat(source, &source_stat) < 0)) { |
45 | perror_msg("%s", source); | 46 | perror_msg("%s", source); |
46 | return -1; | 47 | return -1; |
@@ -64,7 +65,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
64 | DIR *dp; | 65 | DIR *dp; |
65 | struct dirent *d; | 66 | struct dirent *d; |
66 | 67 | ||
67 | if (!(flags & CP_RECUR)) { | 68 | if (!(flags & FILEUTILS_RECUR)) { |
68 | error_msg("%s: omitting directory", source); | 69 | error_msg("%s: omitting directory", source); |
69 | return -1; | 70 | return -1; |
70 | } | 71 | } |
@@ -80,7 +81,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
80 | saved_umask = umask(0); | 81 | saved_umask = umask(0); |
81 | 82 | ||
82 | mode = source_stat.st_mode; | 83 | mode = source_stat.st_mode; |
83 | if (!(flags & CP_PRESERVE_STATUS)) | 84 | if (!(flags & FILEUTILS_PRESERVE_STATUS)) |
84 | mode = source_stat.st_mode & ~saved_umask; | 85 | mode = source_stat.st_mode & ~saved_umask; |
85 | mode |= S_IRWXU; | 86 | mode |= S_IRWXU; |
86 | 87 | ||
@@ -125,14 +126,14 @@ int copy_file(const char *source, const char *dest, int flags) | |||
125 | FILE *sfp, *dfp; | 126 | FILE *sfp, *dfp; |
126 | 127 | ||
127 | if (dest_exists) { | 128 | if (dest_exists) { |
128 | if (flags & CP_INTERACTIVE) { | 129 | if (flags & FILEUTILS_INTERACTIVE) { |
129 | fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); | 130 | fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); |
130 | if (!ask_confirmation()) | 131 | if (!ask_confirmation()) |
131 | return 0; | 132 | return 0; |
132 | } | 133 | } |
133 | 134 | ||
134 | if ((dfp = fopen(dest, "w")) == NULL) { | 135 | if ((dfp = fopen(dest, "w")) == NULL) { |
135 | if (!(flags & CP_FORCE)) { | 136 | if (!(flags & FILEUTILS_FORCE)) { |
136 | perror_msg("unable to open `%s'", dest); | 137 | perror_msg("unable to open `%s'", dest); |
137 | return -1; | 138 | return -1; |
138 | } | 139 | } |
@@ -187,7 +188,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
187 | saved_umask = umask(0); | 188 | saved_umask = umask(0); |
188 | 189 | ||
189 | mode = source_stat.st_mode; | 190 | mode = source_stat.st_mode; |
190 | if (!(flags & CP_PRESERVE_STATUS)) | 191 | if (!(flags & FILEUTILS_PRESERVE_STATUS)) |
191 | mode = source_stat.st_mode & ~saved_umask; | 192 | mode = source_stat.st_mode & ~saved_umask; |
192 | mode |= S_IRWXU; | 193 | mode |= S_IRWXU; |
193 | 194 | ||
@@ -213,7 +214,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
213 | } | 214 | } |
214 | 215 | ||
215 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | 216 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) |
216 | if (flags & CP_PRESERVE_STATUS) | 217 | if (flags & FILEUTILS_PRESERVE_STATUS) |
217 | if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0) | 218 | if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0) |
218 | perror_msg("unable to preserve ownership of `%s'", dest); | 219 | perror_msg("unable to preserve ownership of `%s'", dest); |
219 | #endif | 220 | #endif |
@@ -225,7 +226,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
225 | 226 | ||
226 | end: | 227 | end: |
227 | 228 | ||
228 | if (flags & CP_PRESERVE_STATUS) { | 229 | if (flags & FILEUTILS_PRESERVE_STATUS) { |
229 | struct utimbuf times; | 230 | struct utimbuf times; |
230 | 231 | ||
231 | times.actime = source_stat.st_atime; | 232 | times.actime = source_stat.st_atime; |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 4eeb99343..404d7076c 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
@@ -255,11 +255,11 @@ extern int gz_open(FILE *compressed_file, int *pid); | |||
255 | /* extern int convert(char *fn, int ConvType); */ | 255 | /* extern int convert(char *fn, int ConvType); */ |
256 | 256 | ||
257 | enum { | 257 | enum { |
258 | CP_PRESERVE_STATUS = 1, | 258 | FILEUTILS_PRESERVE_STATUS = 1, |
259 | CP_PRESERVE_SYMLINKS = 2, | 259 | FILEUTILS_PRESERVE_SYMLINKS = 2, |
260 | CP_RECUR = 4, | 260 | FILEUTILS_RECUR = 4, |
261 | CP_FORCE = 8, | 261 | FILEUTILS_FORCE = 8, |
262 | CP_INTERACTIVE = 16 | 262 | FILEUTILS_INTERACTIVE = 16 |
263 | }; | 263 | }; |
264 | 264 | ||
265 | extern const char *applet_name; | 265 | extern const char *applet_name; |
@@ -30,7 +30,7 @@ | |||
30 | 30 | ||
31 | #include "busybox.h" | 31 | #include "busybox.h" |
32 | 32 | ||
33 | static int flags = CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS; | 33 | static int flags; |
34 | 34 | ||
35 | static int remove_file(const char *path, struct stat *statbuf, void *junk) | 35 | static int remove_file(const char *path, struct stat *statbuf, void *junk) |
36 | { | 36 | { |
@@ -88,8 +88,8 @@ static int manual_rename(const char *source, const char *dest) | |||
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | if (copy_file(source, dest, | 91 | if (copy_file(source, dest, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS | |
92 | CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS) < 0) | 92 | FILEUTILS_PRESERVE_SYMLINKS) < 0) |
93 | return -1; | 93 | return -1; |
94 | 94 | ||
95 | if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file, | 95 | if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file, |
@@ -112,9 +112,9 @@ static int move_file(const char *source, const char *dest) | |||
112 | dest_exists = 0; | 112 | dest_exists = 0; |
113 | } | 113 | } |
114 | 114 | ||
115 | if (dest_exists && !(flags & CP_FORCE) && | 115 | if (dest_exists && !(flags & FILEUTILS_FORCE) && |
116 | ((access(dest, W_OK) < 0 && isatty(0)) || | 116 | ((access(dest, W_OK) < 0 && isatty(0)) || |
117 | (flags & CP_INTERACTIVE))) { | 117 | (flags & FILEUTILS_INTERACTIVE))) { |
118 | fprintf(stderr, "mv: overwrite `%s'? ", dest); | 118 | fprintf(stderr, "mv: overwrite `%s'? ", dest); |
119 | if (!ask_confirmation()) | 119 | if (!ask_confirmation()) |
120 | return 0; | 120 | return 0; |
@@ -140,12 +140,12 @@ extern int mv_main(int argc, char **argv) | |||
140 | while ((opt = getopt(argc, argv, "fi")) != -1) | 140 | while ((opt = getopt(argc, argv, "fi")) != -1) |
141 | switch (opt) { | 141 | switch (opt) { |
142 | case 'f': | 142 | case 'f': |
143 | flags &= ~CP_INTERACTIVE; | 143 | flags &= ~FILEUTILS_INTERACTIVE; |
144 | flags |= CP_FORCE; | 144 | flags |= FILEUTILS_FORCE; |
145 | break; | 145 | break; |
146 | case 'i': | 146 | case 'i': |
147 | flags &= ~CP_FORCE; | 147 | flags &= ~FILEUTILS_FORCE; |
148 | flags |= CP_INTERACTIVE; | 148 | flags |= FILEUTILS_INTERACTIVE; |
149 | break; | 149 | break; |
150 | default: | 150 | default: |
151 | show_usage(); | 151 | show_usage(); |