From cc8ed39b240180b58810784f844e253263594ac3 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 5 Oct 1999 16:24:54 +0000 Subject: Initial revision --- coreutils/mv.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 coreutils/mv.c (limited to 'coreutils/mv.c') diff --git a/coreutils/mv.c b/coreutils/mv.c new file mode 100644 index 000000000..22c4a1207 --- /dev/null +++ b/coreutils/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