113643Ssam #ifndef lint 2*23597Sbloom static char sccsid[] = "@(#)cpmv.c 5.4 (Berkeley) 06/19/85"; 313643Ssam #endif 413643Ssam 513643Ssam #include "uucp.h" 613643Ssam #include <sys/stat.h> 713643Ssam 8*23597Sbloom /*LINTLIBRARY*/ 9*23597Sbloom 10*23597Sbloom /* 11*23597Sbloom * copy f1 to f2 1213643Ssam * 1313643Ssam * return - 0 ok | FAIL failed 1413643Ssam */ 1513643Ssam 1613643Ssam xcp(f1, f2) 1713643Ssam char *f1, *f2; 1813643Ssam { 1913643Ssam char buf[BUFSIZ]; 2013643Ssam register int len; 2117835Sralph register int fp1, fp2; 2213643Ssam char *lastpart(); 2317835Sralph char full[100]; 2413643Ssam struct stat s; 2513643Ssam 2617835Sralph if ((fp1 = open(subfile(f1), 0)) < 0) 2717835Sralph return FAIL; 2813643Ssam strcpy(full, f2); 2913643Ssam if (stat(subfile(f2), &s) == 0) { 3013643Ssam /* check for directory */ 3113643Ssam if ((s.st_mode & S_IFMT) == S_IFDIR) { 3213643Ssam strcat(full, "/"); 3313643Ssam strcat(full, lastpart(f1)); 3413643Ssam } 3513643Ssam } 3613643Ssam DEBUG(4, "full %s\n", full); 3717835Sralph if ((fp2 = creat(subfile(full), 0666)) < 0) { 3817835Sralph close(fp1); 3917835Sralph return FAIL; 4013643Ssam } 4117835Sralph while((len = read(fp1, buf, BUFSIZ)) > 0) 4217835Sralph if (write(fp2, buf, len) != len) { 4317835Sralph len = -1; 4417835Sralph break; 4517835Sralph } 4617835Sralph 4717835Sralph close(fp1); 4817835Sralph close(fp2); 4917835Sralph return len < 0 ? FAIL: SUCCESS; 5013643Ssam } 5113643Ssam 5213643Ssam 5313643Ssam /* 5413643Ssam * xmv(f1, f2) move f1 to f2 5513643Ssam * char * f1, *f2; 5613643Ssam * 5713643Ssam * return 0 ok | FAIL failed 5813643Ssam */ 5913643Ssam 6013643Ssam xmv(f1, f2) 6113643Ssam register char *f1, *f2; 6213643Ssam { 6313643Ssam register int ret; 6413643Ssam 6513643Ssam if (link(subfile(f1), subfile(f2)) < 0) { 6613643Ssam /* copy file */ 6713643Ssam ret = xcp(f1, f2); 6813643Ssam if (ret == 0) 6913643Ssam unlink(subfile(f1)); 7017835Sralph return ret; 7113643Ssam } 7213643Ssam unlink(subfile(f1)); 7317835Sralph return 0; 7413643Ssam } 75