1*13643Ssam #ifndef lint 2*13643Ssam static char sccsid[] = "@(#)cpmv.c 5.1 (Berkeley) 07/02/83"; 3*13643Ssam #endif 4*13643Ssam 5*13643Ssam #include "uucp.h" 6*13643Ssam #include <sys/types.h> 7*13643Ssam #include <sys/stat.h> 8*13643Ssam 9*13643Ssam 10*13643Ssam /*** 11*13643Ssam * xcp(f1, f2) copy f1 to f2 12*13643Ssam * char *f1, *f2; 13*13643Ssam * 14*13643Ssam * return - 0 ok | FAIL failed 15*13643Ssam */ 16*13643Ssam 17*13643Ssam xcp(f1, f2) 18*13643Ssam char *f1, *f2; 19*13643Ssam { 20*13643Ssam char buf[BUFSIZ]; 21*13643Ssam register int len; 22*13643Ssam register FILE *fp1, *fp2; 23*13643Ssam char *lastpart(); 24*13643Ssam char full[100]; 25*13643Ssam struct stat s; 26*13643Ssam 27*13643Ssam if ((fp1 = fopen(subfile(f1), "r")) == NULL) 28*13643Ssam return(FAIL); 29*13643Ssam strcpy(full, f2); 30*13643Ssam if (stat(subfile(f2), &s) == 0) { 31*13643Ssam /* check for directory */ 32*13643Ssam if ((s.st_mode & S_IFMT) == S_IFDIR) { 33*13643Ssam strcat(full, "/"); 34*13643Ssam strcat(full, lastpart(f1)); 35*13643Ssam } 36*13643Ssam } 37*13643Ssam DEBUG(4, "full %s\n", full); 38*13643Ssam if ((fp2 = fopen(subfile(full), "w")) == NULL) { 39*13643Ssam fclose(fp1); 40*13643Ssam return(FAIL); 41*13643Ssam } 42*13643Ssam while((len = fread(buf, sizeof (char), BUFSIZ, fp1)) > 0) 43*13643Ssam fwrite(buf, sizeof (char), len, fp2); 44*13643Ssam fclose(fp1); 45*13643Ssam fclose(fp2); 46*13643Ssam return(0); 47*13643Ssam } 48*13643Ssam 49*13643Ssam 50*13643Ssam /* 51*13643Ssam * xmv(f1, f2) move f1 to f2 52*13643Ssam * char * f1, *f2; 53*13643Ssam * 54*13643Ssam * return 0 ok | FAIL failed 55*13643Ssam */ 56*13643Ssam 57*13643Ssam xmv(f1, f2) 58*13643Ssam register char *f1, *f2; 59*13643Ssam { 60*13643Ssam register int ret; 61*13643Ssam 62*13643Ssam if (link(subfile(f1), subfile(f2)) < 0) { 63*13643Ssam /* copy file */ 64*13643Ssam ret = xcp(f1, f2); 65*13643Ssam if (ret == 0) 66*13643Ssam unlink(subfile(f1)); 67*13643Ssam return(ret); 68*13643Ssam } 69*13643Ssam unlink(subfile(f1)); 70*13643Ssam return(0); 71*13643Ssam } 72