diff options
author | Jim Meyering <jim@meyering.net> | 1993-08-26 04:38:30 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1993-08-26 04:38:30 +0000 |
commit | 429043125e1842b92f1cdbc6c0a2772316c9d34e (patch) | |
tree | a63cf2e0550e8c034c83e0703eab1dd82ffb9184 /src/mv.c | |
parent | 410da16d0250bcf31c51a160de9eccb92667c7fe (diff) | |
download | coreutils-429043125e1842b92f1cdbc6c0a2772316c9d34e.tar.xz |
merge with 3.8.2
Diffstat (limited to 'src/mv.c')
-rw-r--r-- | src/mv.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -58,6 +58,7 @@ int yesno (); void error (); void strip_trailing_slashes (); int eaccess_stat (); +char *stpcpy (); static int copy_reg (); static int do_move (); @@ -188,6 +189,17 @@ main (argc, argv) exit (errors); } +/* If PATH is an existing directory, return nonzero, else 0. */ + +static int +is_real_dir (path) + char *path; +{ + struct stat stats; + + return lstat (path, &stats) == 0 && S_ISDIR (stats.st_mode); +} + /* Move file SOURCE onto DEST. Handles the case when DEST is a directory. Return 0 if successful, 1 if an error occurred. */ @@ -198,7 +210,8 @@ movefile (source, dest) { strip_trailing_slashes (source); - if (isdir (dest)) + if ((dest[strlen (dest) - 1] == '/' && !is_real_dir (source)) + || isdir (dest)) { /* Target is a directory; build full target filename. */ char *base; @@ -206,7 +219,7 @@ movefile (source, dest) base = basename (source); new_dest = (char *) alloca (strlen (dest) + 1 + strlen (base) + 1); - sprintf (new_dest, "%s/%s", dest, base); + stpcpy (stpcpy (stpcpy (new_dest, dest), "/"), base); return do_move (source, new_dest); } else |