diff options
Diffstat (limited to 'cp_mv.c')
-rw-r--r-- | cp_mv.c | 39 |
1 files changed, 18 insertions, 21 deletions
@@ -89,8 +89,7 @@ static void name_too_long__exit (void) __attribute__((noreturn)); | |||
89 | static | 89 | static |
90 | void name_too_long__exit (void) | 90 | void name_too_long__exit (void) |
91 | { | 91 | { |
92 | fprintf(stderr, name_too_long, applet_name); | 92 | fatalError(name_too_long); |
93 | exit(FALSE); | ||
94 | } | 93 | } |
95 | 94 | ||
96 | static void | 95 | static void |
@@ -124,14 +123,14 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk) | |||
124 | 123 | ||
125 | if (srcDirFlag == TRUE) { | 124 | if (srcDirFlag == TRUE) { |
126 | if (recursiveFlag == FALSE) { | 125 | if (recursiveFlag == FALSE) { |
127 | fprintf(stderr, omitting_directory, applet_name, baseSrcName); | 126 | errorMsg(omitting_directory, baseSrcName); |
128 | return TRUE; | 127 | return TRUE; |
129 | } | 128 | } |
130 | srcBasename = (strstr(fileName, baseSrcName) | 129 | srcBasename = (strstr(fileName, baseSrcName) |
131 | + strlen(baseSrcName)); | 130 | + strlen(baseSrcName)); |
132 | 131 | ||
133 | if (destLen + strlen(srcBasename) > BUFSIZ) { | 132 | if (destLen + strlen(srcBasename) > BUFSIZ) { |
134 | fprintf(stderr, name_too_long, applet_name); | 133 | errorMsg(name_too_long); |
135 | return FALSE; | 134 | return FALSE; |
136 | } | 135 | } |
137 | strcat(destName, srcBasename); | 136 | strcat(destName, srcBasename); |
@@ -145,8 +144,8 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk) | |||
145 | if (mv_Action_first_time && (dz_i == is_mv)) { | 144 | if (mv_Action_first_time && (dz_i == is_mv)) { |
146 | mv_Action_first_time = errno = 0; | 145 | mv_Action_first_time = errno = 0; |
147 | if (rename(fileName, destName) < 0 && errno != EXDEV) { | 146 | if (rename(fileName, destName) < 0 && errno != EXDEV) { |
148 | fprintf(stderr, "%s: rename(%s, %s): %s\n", | 147 | errorMsg("rename(%s, %s): %s\n", fileName, destName, |
149 | applet_name, fileName, destName, strerror(errno)); | 148 | strerror(errno)); |
150 | goto do_copyFile; /* Try anyway... */ | 149 | goto do_copyFile; /* Try anyway... */ |
151 | } | 150 | } |
152 | else if (errno == EXDEV) | 151 | else if (errno == EXDEV) |
@@ -158,8 +157,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk) | |||
158 | if (preserveFlag == TRUE && statbuf->st_nlink > 1) { | 157 | if (preserveFlag == TRUE && statbuf->st_nlink > 1) { |
159 | if (is_in_ino_dev_hashtable(statbuf, &name)) { | 158 | if (is_in_ino_dev_hashtable(statbuf, &name)) { |
160 | if (link(name, destName) < 0) { | 159 | if (link(name, destName) < 0) { |
161 | fprintf(stderr, "%s: link(%s, %s): %s\n", | 160 | errorMsg("link(%s, %s): %s\n", name, destName, strerror(errno)); |
162 | applet_name, name, destName, strerror(errno)); | ||
163 | return FALSE; | 161 | return FALSE; |
164 | } | 162 | } |
165 | return TRUE; | 163 | return TRUE; |
@@ -178,11 +176,11 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk) | |||
178 | 176 | ||
179 | if (S_ISDIR(statbuf->st_mode)) { | 177 | if (S_ISDIR(statbuf->st_mode)) { |
180 | if (rmdir(fileName) < 0) { | 178 | if (rmdir(fileName) < 0) { |
181 | fprintf(stderr, "%s: rmdir(%s): %s\n", applet_name, fileName, strerror(errno)); | 179 | errorMsg("rmdir(%s): %s\n", fileName, strerror(errno)); |
182 | status = FALSE; | 180 | status = FALSE; |
183 | } | 181 | } |
184 | } else if (unlink(fileName) < 0) { | 182 | } else if (unlink(fileName) < 0) { |
185 | fprintf(stderr, "%s: unlink(%s): %s\n", applet_name, fileName, strerror(errno)); | 183 | errorMsg("unlink(%s): %s\n", fileName, strerror(errno)); |
186 | status = FALSE; | 184 | status = FALSE; |
187 | } | 185 | } |
188 | return status; | 186 | return status; |
@@ -236,7 +234,7 @@ extern int cp_mv_main(int argc, char **argv) | |||
236 | 234 | ||
237 | 235 | ||
238 | if (strlen(argv[argc - 1]) > BUFSIZ) { | 236 | if (strlen(argv[argc - 1]) > BUFSIZ) { |
239 | fprintf(stderr, name_too_long, "cp"); | 237 | errorMsg(name_too_long); |
240 | goto exit_false; | 238 | goto exit_false; |
241 | } | 239 | } |
242 | strcpy(baseDestName, argv[argc - 1]); | 240 | strcpy(baseDestName, argv[argc - 1]); |
@@ -246,7 +244,7 @@ extern int cp_mv_main(int argc, char **argv) | |||
246 | 244 | ||
247 | destDirFlag = isDirectory(baseDestName, TRUE, &destStatBuf); | 245 | destDirFlag = isDirectory(baseDestName, TRUE, &destStatBuf); |
248 | if ((argc > 3) && destDirFlag == FALSE) { | 246 | if ((argc > 3) && destDirFlag == FALSE) { |
249 | fprintf(stderr, not_a_directory, "cp", baseDestName); | 247 | errorMsg(not_a_directory, baseDestName); |
250 | goto exit_false; | 248 | goto exit_false; |
251 | } | 249 | } |
252 | 250 | ||
@@ -272,29 +270,28 @@ extern int cp_mv_main(int argc, char **argv) | |||
272 | char *pushd, *d, *p; | 270 | char *pushd, *d, *p; |
273 | 271 | ||
274 | if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) { | 272 | if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) { |
275 | fprintf(stderr, "%s: getcwd(): %s\n", applet_name, strerror(errno)); | 273 | errorMsg("getcwd(): %s\n", strerror(errno)); |
276 | continue; | 274 | continue; |
277 | } | 275 | } |
278 | if (chdir(baseDestName) < 0) { | 276 | if (chdir(baseDestName) < 0) { |
279 | fprintf(stderr, "%s: chdir(%s): %s\n", applet_name, baseSrcName, strerror(errno)); | 277 | errorMsg("chdir(%s): %s\n", baseSrcName, strerror(errno)); |
280 | continue; | 278 | continue; |
281 | } | 279 | } |
282 | if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) { | 280 | if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) { |
283 | fprintf(stderr, "%s: getcwd(): %s\n", applet_name, strerror(errno)); | 281 | errorMsg("getcwd(): %s\n", strerror(errno)); |
284 | continue; | 282 | continue; |
285 | } | 283 | } |
286 | while (!state && *d != '\0') { | 284 | while (!state && *d != '\0') { |
287 | if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */ | 285 | if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */ |
288 | fprintf(stderr, "%s: stat(%s) :%s\n", applet_name, d, strerror(errno)); | 286 | errorMsg("stat(%s): %s\n", d, strerror(errno)); |
289 | state = -1; | 287 | state = -1; |
290 | continue; | 288 | continue; |
291 | } | 289 | } |
292 | if ((sb.st_ino == srcStatBuf.st_ino) && | 290 | if ((sb.st_ino == srcStatBuf.st_ino) && |
293 | (sb.st_dev == srcStatBuf.st_dev)) { | 291 | (sb.st_dev == srcStatBuf.st_dev)) { |
294 | fprintf(stderr, | 292 | errorMsg("Cannot %s `%s' into a subdirectory of itself, " |
295 | "%s: Cannot %s `%s' " | 293 | "`%s/%s'\n", applet_name, baseSrcName, |
296 | "into a subdirectory of itself, `%s/%s'\n", | 294 | baseDestName, baseSrcName); |
297 | applet_name, applet_name, baseSrcName, baseDestName, baseSrcName); | ||
298 | state = -1; | 295 | state = -1; |
299 | continue; | 296 | continue; |
300 | } | 297 | } |
@@ -303,7 +300,7 @@ extern int cp_mv_main(int argc, char **argv) | |||
303 | } | 300 | } |
304 | } | 301 | } |
305 | if (chdir(pushd) < 0) { | 302 | if (chdir(pushd) < 0) { |
306 | fprintf(stderr, "%s: chdir(%s): %s\n", applet_name, pushd, strerror(errno)); | 303 | errorMsg("chdir(%s): %s\n", pushd, strerror(errno)); |
307 | free(pushd); | 304 | free(pushd); |
308 | free(d); | 305 | free(d); |
309 | continue; | 306 | continue; |