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