Commit | Line | Data |
---|---|---|
7ea0db89 | 1 | #ifndef lint |
0801d743 | 2 | static char *sccsid = "@(#)strip.c 4.5 (Berkeley) %G%"; |
7ea0db89 SL |
3 | #endif |
4 | ||
b261d7a4 BJ |
5 | #include <a.out.h> |
6 | #include <signal.h> | |
0801d743 SL |
7 | #include <stdio.h> |
8 | #include <sys/file.h> | |
b261d7a4 | 9 | |
0801d743 | 10 | struct exec head; |
b261d7a4 | 11 | int status; |
7ea0db89 | 12 | int pagesize; |
b261d7a4 BJ |
13 | |
14 | main(argc, argv) | |
0801d743 | 15 | char *argv[]; |
b261d7a4 BJ |
16 | { |
17 | register i; | |
18 | ||
7ea0db89 | 19 | pagesize = getpagesize(); |
b261d7a4 BJ |
20 | signal(SIGHUP, SIG_IGN); |
21 | signal(SIGINT, SIG_IGN); | |
22 | signal(SIGQUIT, SIG_IGN); | |
0801d743 | 23 | for (i = 1; i < argc; i++) { |
b261d7a4 | 24 | strip(argv[i]); |
0801d743 | 25 | if (status > 1) |
b261d7a4 BJ |
26 | break; |
27 | } | |
b261d7a4 BJ |
28 | exit(status); |
29 | } | |
30 | ||
31 | strip(name) | |
0801d743 | 32 | char *name; |
b261d7a4 BJ |
33 | { |
34 | register f; | |
35 | long size; | |
b261d7a4 | 36 | |
0801d743 SL |
37 | f = open(name, O_RDWR); |
38 | if (f < 0) { | |
39 | fprintf(stderr, "strip: "); perror(name); | |
b261d7a4 BJ |
40 | status = 1; |
41 | goto out; | |
42 | } | |
0801d743 SL |
43 | if (read(f, (char *)&head, sizeof (head)) < 0 || N_BADMAG(head)) { |
44 | printf("strip: %s not in a.out format\n", name); | |
b261d7a4 BJ |
45 | status = 1; |
46 | goto out; | |
47 | } | |
48 | if ((head.a_syms == 0) && (head.a_trsize == 0) && (head.a_drsize ==0)) { | |
0801d743 | 49 | printf("strip: %s already stripped\n", name); |
b261d7a4 BJ |
50 | goto out; |
51 | } | |
52 | size = (long)head.a_text + head.a_data; | |
0801d743 | 53 | head.a_syms = head.a_trsize = head.a_drsize = 0; |
b261d7a4 | 54 | if (head.a_magic == ZMAGIC) |
7ea0db89 | 55 | size += pagesize - sizeof (head); |
0801d743 SL |
56 | if (ftruncate(f, size + sizeof (head)) < 0) { |
57 | fprintf("strip: "); perror(name); | |
b261d7a4 BJ |
58 | status = 1; |
59 | goto out; | |
60 | } | |
0801d743 SL |
61 | (void) lseek(f, (long)0, L_SET); |
62 | (void) write(f, (char *)&head, sizeof (head)); | |
b261d7a4 BJ |
63 | out: |
64 | close(f); | |
65 | } |