source: trunk/minix/commands/simple/size.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.4 KB
Line 
1/* size - tell size of an object file Author: Andy Tanenbaum */
2
3#include <sys/types.h>
4#include <fcntl.h>
5#include <a.out.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <stdio.h>
9
10int heading; /* set when heading printed */
11int error;
12
13_PROTOTYPE(int main, (int argc, char **argv));
14_PROTOTYPE(void size, (char *name));
15
16int main(argc, argv)
17int argc;
18char *argv[];
19{
20 int i;
21
22 if (argc == 1) {
23 size("a.out");
24 exit(error);
25 }
26 for (i = 1; i < argc; i++) size(argv[i]);
27 return(error);
28}
29
30
31
32void size(name)
33char *name;
34{
35 int fd, separate;
36 long dynam, allmem;
37 struct exec exec;
38
39 if ((fd = open(name, O_RDONLY)) < 0) {
40 fprintf(stderr, "size: can't open %s\n", name);
41 error = 1;
42 return;
43 }
44 if (read(fd, (char *)&exec, sizeof(struct exec)) != sizeof(struct exec)) {
45 fprintf(stderr, "size: %s: header too short\n", name);
46 error = 1;
47 close(fd);
48 return;
49 }
50 if (BADMAG(exec)) {
51 fprintf(stderr, "size: %s not an object file\n", name);
52 error = 1;
53 close(fd);
54 return;
55 }
56 separate = (exec.a_flags & A_SEP ? 1 : 0);
57 dynam = exec.a_total - exec.a_text - exec.a_data - exec.a_bss;
58 if (separate) dynam += exec.a_text;
59 allmem = (separate ? exec.a_total + exec.a_text : exec.a_total);
60 if (heading++ == 0) printf(" text data bss stack memory\n");
61 printf("%7ld %7ld %7ld %8ld %8ld %s\n",
62 exec.a_text, exec.a_data, exec.a_bss, dynam, allmem, name);
63 close(fd);
64}
Note: See TracBrowser for help on using the repository browser.