From 1f3e8dc36947bdcc2d008fba3cdc29e2c79f9c27 Mon Sep 17 00:00:00 2001 From: andersen Date: Tue, 5 Oct 1999 16:24:54 +0000 Subject: Initial revision git-svn-id: svn://busybox.net/trunk/busybox@5 69ca8d6d-28ef-0310-b511-8ec308f3f277 --- mv.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 mv.c (limited to 'mv.c') diff --git a/mv.c b/mv.c new file mode 100644 index 000000000..22c4a1207 --- /dev/null +++ b/mv.c @@ -0,0 +1,38 @@ +#include "internal.h" +#include +#include + +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); +} -- cgit v1.2.3-55-g6feb