diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /libbb/copy_file.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'libbb/copy_file.c')
-rw-r--r-- | libbb/copy_file.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 23a2d75a3..81c547479 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -43,19 +43,19 @@ int copy_file(const char *source, const char *dest, int flags) | |||
43 | lstat(source, &source_stat) < 0) || | 43 | lstat(source, &source_stat) < 0) || |
44 | ((flags & FILEUTILS_DEREFERENCE) && | 44 | ((flags & FILEUTILS_DEREFERENCE) && |
45 | stat(source, &source_stat) < 0)) { | 45 | stat(source, &source_stat) < 0)) { |
46 | perror_msg("%s", source); | 46 | bb_perror_msg("%s", source); |
47 | return -1; | 47 | return -1; |
48 | } | 48 | } |
49 | 49 | ||
50 | if (lstat(dest, &dest_stat) < 0) { | 50 | if (lstat(dest, &dest_stat) < 0) { |
51 | if (errno != ENOENT) { | 51 | if (errno != ENOENT) { |
52 | perror_msg("unable to stat `%s'", dest); | 52 | bb_perror_msg("unable to stat `%s'", dest); |
53 | return -1; | 53 | return -1; |
54 | } | 54 | } |
55 | } else { | 55 | } else { |
56 | if (source_stat.st_dev == dest_stat.st_dev && | 56 | if (source_stat.st_dev == dest_stat.st_dev && |
57 | source_stat.st_ino == dest_stat.st_ino) { | 57 | source_stat.st_ino == dest_stat.st_ino) { |
58 | error_msg("`%s' and `%s' are the same file", source, dest); | 58 | bb_error_msg("`%s' and `%s' are the same file", source, dest); |
59 | return -1; | 59 | return -1; |
60 | } | 60 | } |
61 | dest_exists = 1; | 61 | dest_exists = 1; |
@@ -67,14 +67,14 @@ int copy_file(const char *source, const char *dest, int flags) | |||
67 | mode_t saved_umask = 0; | 67 | mode_t saved_umask = 0; |
68 | 68 | ||
69 | if (!(flags & FILEUTILS_RECUR)) { | 69 | if (!(flags & FILEUTILS_RECUR)) { |
70 | error_msg("%s: omitting directory", source); | 70 | bb_error_msg("%s: omitting directory", source); |
71 | return -1; | 71 | return -1; |
72 | } | 72 | } |
73 | 73 | ||
74 | /* Create DEST. */ | 74 | /* Create DEST. */ |
75 | if (dest_exists) { | 75 | if (dest_exists) { |
76 | if (!S_ISDIR(dest_stat.st_mode)) { | 76 | if (!S_ISDIR(dest_stat.st_mode)) { |
77 | error_msg("`%s' is not a directory", dest); | 77 | bb_error_msg("`%s' is not a directory", dest); |
78 | return -1; | 78 | return -1; |
79 | } | 79 | } |
80 | } else { | 80 | } else { |
@@ -88,7 +88,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
88 | 88 | ||
89 | if (mkdir(dest, mode) < 0) { | 89 | if (mkdir(dest, mode) < 0) { |
90 | umask(saved_umask); | 90 | umask(saved_umask); |
91 | perror_msg("cannot create directory `%s'", dest); | 91 | bb_perror_msg("cannot create directory `%s'", dest); |
92 | return -1; | 92 | return -1; |
93 | } | 93 | } |
94 | 94 | ||
@@ -97,7 +97,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
97 | 97 | ||
98 | /* Recursively copy files in SOURCE. */ | 98 | /* Recursively copy files in SOURCE. */ |
99 | if ((dp = opendir(source)) == NULL) { | 99 | if ((dp = opendir(source)) == NULL) { |
100 | perror_msg("unable to open directory `%s'", source); | 100 | bb_perror_msg("unable to open directory `%s'", source); |
101 | status = -1; | 101 | status = -1; |
102 | goto end; | 102 | goto end; |
103 | } | 103 | } |
@@ -121,7 +121,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
121 | 121 | ||
122 | if (!dest_exists && | 122 | if (!dest_exists && |
123 | chmod(dest, source_stat.st_mode & ~saved_umask) < 0) { | 123 | chmod(dest, source_stat.st_mode & ~saved_umask) < 0) { |
124 | perror_msg("unable to change permissions of `%s'", dest); | 124 | bb_perror_msg("unable to change permissions of `%s'", dest); |
125 | status = -1; | 125 | status = -1; |
126 | } | 126 | } |
127 | } else if (S_ISREG(source_stat.st_mode)) { | 127 | } else if (S_ISREG(source_stat.st_mode)) { |
@@ -132,7 +132,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
132 | if (!(flags & FILEUTILS_DEREFERENCE) && | 132 | if (!(flags & FILEUTILS_DEREFERENCE) && |
133 | is_in_ino_dev_hashtable(&source_stat, &link_name)) { | 133 | is_in_ino_dev_hashtable(&source_stat, &link_name)) { |
134 | if (link(link_name, dest) < 0) { | 134 | if (link(link_name, dest) < 0) { |
135 | perror_msg("unable to link `%s'", dest); | 135 | bb_perror_msg("unable to link `%s'", dest); |
136 | return -1; | 136 | return -1; |
137 | } | 137 | } |
138 | 138 | ||
@@ -140,14 +140,14 @@ int copy_file(const char *source, const char *dest, int flags) | |||
140 | } | 140 | } |
141 | #endif | 141 | #endif |
142 | 142 | ||
143 | if ((sfp = wfopen(source, "r")) == NULL) { | 143 | if ((sfp = bb_wfopen(source, "r")) == NULL) { |
144 | return -1; | 144 | return -1; |
145 | } | 145 | } |
146 | 146 | ||
147 | if (dest_exists) { | 147 | if (dest_exists) { |
148 | if (flags & FILEUTILS_INTERACTIVE) { | 148 | if (flags & FILEUTILS_INTERACTIVE) { |
149 | fprintf(stderr, "%s: overwrite `%s'? ", applet_name, dest); | 149 | fprintf(stderr, "%s: overwrite `%s'? ", bb_applet_name, dest); |
150 | if (!ask_confirmation()) { | 150 | if (!bb_ask_confirmation()) { |
151 | fclose (sfp); | 151 | fclose (sfp); |
152 | return 0; | 152 | return 0; |
153 | } | 153 | } |
@@ -155,13 +155,13 @@ int copy_file(const char *source, const char *dest, int flags) | |||
155 | 155 | ||
156 | if ((dfp = fopen(dest, "w")) == NULL) { | 156 | if ((dfp = fopen(dest, "w")) == NULL) { |
157 | if (!(flags & FILEUTILS_FORCE)) { | 157 | if (!(flags & FILEUTILS_FORCE)) { |
158 | perror_msg("unable to open `%s'", dest); | 158 | bb_perror_msg("unable to open `%s'", dest); |
159 | fclose (sfp); | 159 | fclose (sfp); |
160 | return -1; | 160 | return -1; |
161 | } | 161 | } |
162 | 162 | ||
163 | if (unlink(dest) < 0) { | 163 | if (unlink(dest) < 0) { |
164 | perror_msg("unable to remove `%s'", dest); | 164 | bb_perror_msg("unable to remove `%s'", dest); |
165 | fclose (sfp); | 165 | fclose (sfp); |
166 | return -1; | 166 | return -1; |
167 | } | 167 | } |
@@ -177,22 +177,22 @@ int copy_file(const char *source, const char *dest, int flags) | |||
177 | (dfp = fdopen(fd, "w")) == NULL) { | 177 | (dfp = fdopen(fd, "w")) == NULL) { |
178 | if (fd >= 0) | 178 | if (fd >= 0) |
179 | close(fd); | 179 | close(fd); |
180 | perror_msg("unable to open `%s'", dest); | 180 | bb_perror_msg("unable to open `%s'", dest); |
181 | fclose (sfp); | 181 | fclose (sfp); |
182 | return -1; | 182 | return -1; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | if (copyfd(fileno(sfp), fileno(dfp), 0) == -1) | 186 | if (bb_copyfd(fileno(sfp), fileno(dfp), 0) == -1) |
187 | status = -1; | 187 | status = -1; |
188 | 188 | ||
189 | if (fclose(dfp) < 0) { | 189 | if (fclose(dfp) < 0) { |
190 | perror_msg("unable to close `%s'", dest); | 190 | bb_perror_msg("unable to close `%s'", dest); |
191 | status = -1; | 191 | status = -1; |
192 | } | 192 | } |
193 | 193 | ||
194 | if (fclose(sfp) < 0) { | 194 | if (fclose(sfp) < 0) { |
195 | perror_msg("unable to close `%s'", source); | 195 | bb_perror_msg("unable to close `%s'", source); |
196 | status = -1; | 196 | status = -1; |
197 | } | 197 | } |
198 | } | 198 | } |
@@ -202,23 +202,23 @@ int copy_file(const char *source, const char *dest, int flags) | |||
202 | 202 | ||
203 | if (dest_exists && | 203 | if (dest_exists && |
204 | ((flags & FILEUTILS_FORCE) == 0 || unlink(dest) < 0)) { | 204 | ((flags & FILEUTILS_FORCE) == 0 || unlink(dest) < 0)) { |
205 | perror_msg("unable to remove `%s'", dest); | 205 | bb_perror_msg("unable to remove `%s'", dest); |
206 | return -1; | 206 | return -1; |
207 | 207 | ||
208 | } | 208 | } |
209 | } else { | 209 | } else { |
210 | error_msg("internal error: unrecognized file type"); | 210 | bb_error_msg("internal error: unrecognized file type"); |
211 | return -1; | 211 | return -1; |
212 | } | 212 | } |
213 | if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) || | 213 | if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) || |
214 | S_ISSOCK(source_stat.st_mode)) { | 214 | S_ISSOCK(source_stat.st_mode)) { |
215 | if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) { | 215 | if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) { |
216 | perror_msg("unable to create `%s'", dest); | 216 | bb_perror_msg("unable to create `%s'", dest); |
217 | return -1; | 217 | return -1; |
218 | } | 218 | } |
219 | } else if (S_ISFIFO(source_stat.st_mode)) { | 219 | } else if (S_ISFIFO(source_stat.st_mode)) { |
220 | if (mkfifo(dest, source_stat.st_mode) < 0) { | 220 | if (mkfifo(dest, source_stat.st_mode) < 0) { |
221 | perror_msg("cannot create fifo `%s'", dest); | 221 | bb_perror_msg("cannot create fifo `%s'", dest); |
222 | return -1; | 222 | return -1; |
223 | } | 223 | } |
224 | } else if (S_ISLNK(source_stat.st_mode)) { | 224 | } else if (S_ISLNK(source_stat.st_mode)) { |
@@ -226,7 +226,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
226 | 226 | ||
227 | lpath = xreadlink(source); | 227 | lpath = xreadlink(source); |
228 | if (symlink(lpath, dest) < 0) { | 228 | if (symlink(lpath, dest) < 0) { |
229 | perror_msg("cannot create symlink `%s'", dest); | 229 | bb_perror_msg("cannot create symlink `%s'", dest); |
230 | return -1; | 230 | return -1; |
231 | } | 231 | } |
232 | free(lpath); | 232 | free(lpath); |
@@ -234,7 +234,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
234 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | 234 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) |
235 | if (flags & FILEUTILS_PRESERVE_STATUS) | 235 | if (flags & FILEUTILS_PRESERVE_STATUS) |
236 | if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0) | 236 | if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0) |
237 | perror_msg("unable to preserve ownership of `%s'", dest); | 237 | bb_perror_msg("unable to preserve ownership of `%s'", dest); |
238 | #endif | 238 | #endif |
239 | 239 | ||
240 | #ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS | 240 | #ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS |
@@ -256,13 +256,13 @@ end: | |||
256 | times.actime = source_stat.st_atime; | 256 | times.actime = source_stat.st_atime; |
257 | times.modtime = source_stat.st_mtime; | 257 | times.modtime = source_stat.st_mtime; |
258 | if (utime(dest, ×) < 0) | 258 | if (utime(dest, ×) < 0) |
259 | perror_msg("unable to preserve times of `%s'", dest); | 259 | bb_perror_msg("unable to preserve times of `%s'", dest); |
260 | if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) { | 260 | if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) { |
261 | source_stat.st_mode &= ~(S_ISUID | S_ISGID); | 261 | source_stat.st_mode &= ~(S_ISUID | S_ISGID); |
262 | perror_msg("unable to preserve ownership of `%s'", dest); | 262 | bb_perror_msg("unable to preserve ownership of `%s'", dest); |
263 | } | 263 | } |
264 | if (chmod(dest, source_stat.st_mode) < 0) | 264 | if (chmod(dest, source_stat.st_mode) < 0) |
265 | perror_msg("unable to preserve permissions of `%s'", dest); | 265 | bb_perror_msg("unable to preserve permissions of `%s'", dest); |
266 | } | 266 | } |
267 | 267 | ||
268 | return status; | 268 | return status; |