BSD 4 development
[unix-history] / usr / src / cmd / uucp / cpmv.c
index 1c36dd5..ea5b80c 100644 (file)
@@ -1,4 +1,6 @@
 #include "uucp.h"
 #include "uucp.h"
+#include <sys/types.h>
+#include <sys/stat.h>
 
 /***
  *     xcp(f1, f2)     copy f1 to f2
 
 /***
  *     xcp(f1, f2)     copy f1 to f2
@@ -13,10 +15,22 @@ char *f1, *f2;
        char buf[BUFSIZ];
        int len;
        FILE *fp1, *fp2;
        char buf[BUFSIZ];
        int len;
        FILE *fp1, *fp2;
+       char *lastpart();
+       char full[100];
+       struct stat s;
 
        if ((fp1 = fopen(f1, "r")) == NULL)
                return(FAIL);
 
        if ((fp1 = fopen(f1, "r")) == NULL)
                return(FAIL);
-       if ((fp2 = fopen(f2, "w")) == NULL) {
+       strcpy(full, f2);
+       if (stat(f2, &s) == 0) {
+               /* check for directory */
+               if ((s.st_mode & S_IFMT) == S_IFDIR) {
+                       strcat(full, "/");
+                       strcat(full, lastpart(f1));
+               }
+       }
+       DEBUG(4, "full %s\n", full);
+       if ((fp2 = fopen(full, "w")) == NULL) {
                fclose(fp1);
                return(FAIL);
        }
                fclose(fp1);
                return(FAIL);
        }