1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: char copyright[] =
9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
10: All rights reserved.\n";
11: #endif not lint
12:
13: #ifndef lint
14: static char sccsid[] = "@(#)strip.c 5.1 (Berkeley) 4/30/85";
15: #endif not lint
16:
17: #include <a.out.h>
18: #include <signal.h>
19: #include <stdio.h>
20: #include <sys/file.h>
21:
22: struct exec head;
23: int status;
24: int pagesize;
25:
26: main(argc, argv)
27: char *argv[];
28: {
29: register i;
30:
31: pagesize = getpagesize();
32: signal(SIGHUP, SIG_IGN);
33: signal(SIGINT, SIG_IGN);
34: signal(SIGQUIT, SIG_IGN);
35: for (i = 1; i < argc; i++) {
36: strip(argv[i]);
37: if (status > 1)
38: break;
39: }
40: exit(status);
41: }
42:
43: strip(name)
44: char *name;
45: {
46: register f;
47: long size;
48:
49: f = open(name, O_RDWR);
50: if (f < 0) {
51: fprintf(stderr, "strip: "); perror(name);
52: status = 1;
53: goto out;
54: }
55: if (read(f, (char *)&head, sizeof (head)) < 0 || N_BADMAG(head)) {
56: printf("strip: %s not in a.out format\n", name);
57: status = 1;
58: goto out;
59: }
60: if ((head.a_syms == 0) && (head.a_trsize == 0) && (head.a_drsize ==0)) {
61: printf("strip: %s already stripped\n", name);
62: goto out;
63: }
64: size = (long)head.a_text + head.a_data;
65: head.a_syms = head.a_trsize = head.a_drsize = 0;
66: if (head.a_magic == ZMAGIC)
67: size += pagesize - sizeof (head);
68: if (ftruncate(f, size + sizeof (head)) < 0) {
69: fprintf("strip: "); perror(name);
70: status = 1;
71: goto out;
72: }
73: (void) lseek(f, (long)0, L_SET);
74: (void) write(f, (char *)&head, sizeof (head));
75: out:
76: close(f);
77: }
Defined functions
main
defined in line
26;
never used
strip
defined in line
43; used 1 times
Defined variables
head
defined in line
22; used 16 times