summaryrefslogtreecommitdiff
path: root/mv.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
commitcc8ed39b240180b58810784f844e253263594ac3 (patch)
tree15feebbb4be9a9168209609f48f0b100f9364420 /mv.c
downloadbusybox-w32-0_29alpha2.tar.gz
busybox-w32-0_29alpha2.tar.bz2
busybox-w32-0_29alpha2.zip
Initial revision0_29alpha2
Diffstat (limited to 'mv.c')
-rw-r--r--mv.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/mv.c b/mv.c
new file mode 100644
index 000000000..22c4a1207
--- /dev/null
+++ b/mv.c
@@ -0,0 +1,38 @@
1#include "internal.h"
2#include <stdio.h>
3#include <errno.h>
4
5const char mv_usage[] = "mv source-file destination-file\n"
6"\t\tmv source-file [source-file ...] destination-directory\n"
7"\n"
8"\tMove the source files to the destination.\n"
9"\n";
10
11extern int
12mv_fn(const struct FileInfo * i)
13{
14 struct stat destination_stat;
15 char d[1024];
16 struct FileInfo n;
17
18 if ( stat(i->destination, &destination_stat) == 0 ) {
19 if ( i->stat.st_ino == destination_stat.st_ino
20 && i->stat.st_dev == destination_stat.st_dev )
21 return 0; /* Move file to itself. */
22 }
23 if ( (destination_stat.st_mode & S_IFMT) == S_IFDIR ) {
24 n = *i;
25 n.destination = join_paths(d, i->destination, basename(i->source));
26 i = &n;
27 }
28 if ( rename(i->source, i->destination) == 0 )
29 return 0;
30 else if ( errno == EXDEV && is_a_directory(i->source) ) {
31 fprintf(stderr
32 ,"%s: Can't move directory across filesystems.\n"
33 ,i->source);
34 return 1;
35 }
36 else
37 return cp_fn(i);
38}