diff options
author | Eric Andersen | 1999-10-05 16:24:54 +0000 |
---|---|---|
committer | Eric Andersen | 1999-10-05 16:24:54 +0000 |
commit | cc8ed39b240180b58810784f844e253263594ac3 (patch) | |
tree | 15feebbb4be9a9168209609f48f0b100f9364420 /coreutils/mv.c | |
download | busybox-cc8ed39b240180b58810784f844e253263594ac3.zip busybox-cc8ed39b240180b58810784f844e253263594ac3.tar.gz |
Initial revision0_29alpha2
Diffstat (limited to 'coreutils/mv.c')
-rw-r--r-- | coreutils/mv.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/coreutils/mv.c b/coreutils/mv.c new file mode 100644 index 0000000..22c4a12 --- /dev/null +++ b/coreutils/mv.c @@ -0,0 +1,38 @@ +#include "internal.h" +#include <stdio.h> +#include <errno.h> + +const char mv_usage[] = "mv source-file destination-file\n" +"\t\tmv source-file [source-file ...] destination-directory\n" +"\n" +"\tMove the source files to the destination.\n" +"\n"; + +extern int +mv_fn(const struct FileInfo * i) +{ + struct stat destination_stat; + char d[1024]; + struct FileInfo n; + + if ( stat(i->destination, &destination_stat) == 0 ) { + if ( i->stat.st_ino == destination_stat.st_ino + && i->stat.st_dev == destination_stat.st_dev ) + return 0; /* Move file to itself. */ + } + if ( (destination_stat.st_mode & S_IFMT) == S_IFDIR ) { + n = *i; + n.destination = join_paths(d, i->destination, basename(i->source)); + i = &n; + } + if ( rename(i->source, i->destination) == 0 ) + return 0; + else if ( errno == EXDEV && is_a_directory(i->source) ) { + fprintf(stderr + ,"%s: Can't move directory across filesystems.\n" + ,i->source); + return 1; + } + else + return cp_fn(i); +} |