xref: /original-bsd/usr.bin/size/size.c (revision 4ec22e22)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 char copyright[] =
10 "@(#) Copyright (c) 1988 Regents of the University of California.\n\
11  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)size.c	4.7 (Berkeley) 06/01/90";
16 #endif /* not lint */
17 
18 #include <sys/param.h>
19 #include <sys/file.h>
20 #include <a.out.h>
21 #include <stdio.h>
22 
23 main(argc, argv)
24 	int argc;
25 	char **argv;
26 {
27 	struct exec head;
28 	u_long total;
29 	int exval, fd, first;
30 
31 	if (!*argv[1])
32 		*argv = "a.out";
33 	else
34 		++argv;
35 	for (first = 1, exval = 0; *argv; ++argv) {
36 		if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
37 			fprintf(stderr, "size: ");
38 			perror(*argv);
39 			exval = 1;
40 			continue;
41 		}
42 		if (read(fd, (char *)&head, sizeof(head)) != sizeof(head) ||
43 		    N_BADMAG(head)) {
44 			fprintf(stderr, "size: %s: not in a.out format.\n",
45 			    *argv);
46 			exval = 1;
47 			continue;
48 		}
49 		(void)close(fd);
50 		if (first) {
51 			first = 0;
52 			printf("text\tdata\tbss\tdec\thex\n");
53 		}
54 		total = head.a_text + head.a_data + head.a_bss;
55 		printf("%lu\t%lu\t%lu\t%lu\t%lx", head.a_text, head.a_data,
56 		    head.a_bss, total, total);
57 		if (argc > 2)
58 			printf("\t%s", *argv);
59 		printf("\n");
60 	}
61 	exit(exval);
62 }
63