1: main(argc, argv)
2: char *argv[];
3: {
4: char *arg;
5: int fflg, rflg;
6:
7: fflg = 0;
8: rflg = 0;
9: while(--argc > 0) {
10:
11: arg = *++argv;
12: if(arg[0] == '-') {
13: if(arg[1] == 'f') {
14: fflg++;
15: continue;
16: }
17: if(arg[1] == 'r') {
18: rflg++;
19: continue;
20: }
21: }
22:
23: rm(arg, fflg, rflg);
24: }
25: }
26:
27: struct stbuf {
28: int dev;
29: int inum;
30: int mode;
31: char nlink;
32: char uid;
33: char gid;
34: char siz0;
35: char siz1;
36: int addr[8];
37: int adate[2];
38: int mdate[2];
39: };
40:
41: rm(arg, fflg, rflg)
42: char arg[];
43: {
44: char *p;
45: int buf[20];
46: int i, b;
47:
48: if(stat(arg, buf)) {
49: printf("%s: non existent\n", arg);
50: return;
51: }
52: if((buf->mode & 060000) == 040000) {
53: if(rflg) {
54: i = fork();
55: if(i == -1) {
56: printf("%s: try again\n", arg);
57: return;
58: }
59: if(i) {
60: while(wait() != i);
61: return;
62: }
63: if(chdir(arg)) {
64: printf("%s: cannot chdir\n", arg);
65: exit();
66: }
67: p = 0;
68: execl("/etc/glob", "glob", "rm", "-r",
69: fflg? "-f": "*", fflg? "*": p, 0);
70: printf("%s: no glob\n", arg);
71: exit();
72: }
73: printf("%s: directory\n", arg);
74: return;
75: }
76:
77: if(!fflg) {
78:
79: if((getuid()&0377) == buf->uid)
80: b = 0200; else
81: b = 2;
82: if((buf->mode & b) == 0 && ttyn(0) != 'x') {
83: printf("%s: %o mode ", arg, buf->mode);
84: i = b = getchar();
85: i = b;
86: while(b != '\n' && b != '\0')
87: b = getchar();
88: if(i != 'y')
89: return;
90: }
91: }
92: if(unlink(arg))
93: printf("%s: not removed\n", arg);
94: }
95:
96: putchar(c)
97: {
98: write(1, &c, 1);
99: }
100:
101: getchar()
102: {
103: char c;
104:
105: if(read(0, &c, 1) != 1) return(0);
106: return(c);
107: }
Defined functions
getchar
defined in line
101; used 26 times
- in line 84-87(2)
- in /usr/source/s2/mail.c line
77-80(2),
87,
111,
155-158(2),
167,
197
- in /usr/source/s2/mkfs.c line
469
- in /usr/source/s2/ptx.c line
102,
111,
119,
159,
170
- in /usr/source/s2/rc.c line
304
- in /usr/source/s2/restor.c line
151,
413,
485,
492-495(2)
- in /usr/source/s2/sa.c line
443,
451
- in /usr/source/s2/su.c line
25
- in /usr/source/s2/uniq.c line
79
main
defined in line
1;
never used
rm
defined in line
41; used 1 times
Defined struct's
stbuf
defined in line
27;
never used