-
Notifications
You must be signed in to change notification settings - Fork 5
/
osize.c
57 lines (47 loc) · 1.12 KB
/
osize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* For now this only works on object files. It's mostly here so I can
* check the assembler output looks valid.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <stdint.h>
#include <ctype.h>
#include "obj.h"
static char *arg0;
static char segname[] = "ATDB???????????U";
static int do_osize(FILE *fp, const char *name)
{
int i;
static struct objhdr oh;
if (fread(&oh, sizeof(oh), 1, fp) != 1 ||
oh.o_magic != MAGIC_OBJ) {
fprintf(stderr, "%s: %s: not a valid object file.\n", arg0, name);
return 1;
}
for(i = 0; i < 8; i++)
printf("%s: %c %4x\n", name, segname[i], oh.o_size[i]);
return 0;
}
int main(int argc, char *argv[])
{
int n = 1;
int err = 0;
arg0 = argv[0];
if (argc == 1)
do_osize(stdin, "-");
else while (n < argc) {
FILE *fp = fopen(argv[n], "r");
if (fp == NULL) {
perror(argv[n]);
err |= 1;
} else {
err |= do_osize(fp, argv[n]);
fclose(fp);
}
n++;
}
exit(err);
}