Commit | Line | Data |
---|---|---|
01995545 BJ |
1 | /* Copyright (c) 1979 Regents of the University of California */ |
2 | /* | |
3 | * Remove stuff in /tmp owned by the invoker. | |
4 | */ | |
5 | #include <retrofit.h> | |
6 | #include <sys/types.h> | |
7 | #include <sys/stat.h> | |
8 | #include <stdio.h> | |
9 | #include <sys/dir.h> | |
10 | ||
11 | struct direct dirent[2]; | |
12 | ||
13 | main() | |
14 | { | |
15 | struct stat stbuf; | |
16 | register int uid; | |
17 | ||
18 | uid = getuid(); | |
19 | if (chdir("/tmp") < 0) { | |
20 | perror("/tmp"); | |
21 | exit(1); | |
22 | } | |
23 | if (freopen(".", "r", stdin) == NULL) | |
24 | exit(1); | |
25 | while (fread((char *) &dirent[0], sizeof (struct direct), 1, stdin) == 1) { | |
26 | #define ent dirent[0] | |
27 | if (ent.d_ino == 0) | |
28 | continue; | |
29 | if (stat(ent.d_name, &stbuf)) | |
30 | continue; | |
31 | if (!strcmp(ent.d_name, ".") || !strcmp(ent.d_name, "..")) | |
32 | continue; | |
33 | if (stbuf.st_uid != uid) | |
34 | continue; | |
35 | if ((stbuf.st_mode & S_IFMT) != S_IFREG) | |
36 | continue; | |
37 | if (unlink(ent.d_name)) | |
38 | continue; | |
39 | printf("%s\n", ent.d_name); | |
40 | } | |
41 | exit(0); | |
42 | } |