Annotation of 42BSD/usr.bin/uucp/cpmv.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.