-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflat.c
47 lines (39 loc) · 1.33 KB
/
flat.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
#include <stdio.h>
#include "flat.h"
int flat_read_header(FILE *fp, struct flat_hdr *header)
{
rewind(fp);
fread(header->magic, sizeof(char), 4, fp);
if (memcmp(&header->magic, FLTMAGIC, 4) != 0)
return 2;
fread(&header->rev, sizeof(unsigned int), 1, fp);
fread(&header->entry, sizeof(unsigned int), 1, fp);
fread(&header->data_start, sizeof(unsigned int), 1, fp);
fread(&header->data_end, sizeof(unsigned int), 1, fp);
fread(&header->bss_end, sizeof(unsigned int), 1, fp);
fread(&header->stack_size, sizeof(unsigned int), 1, fp);
fread(&header->reloc_start, sizeof(unsigned int), 1, fp);
fread(&header->reloc_count, sizeof(unsigned int), 1, fp);
fread(&header->flags, sizeof(unsigned int), 1, fp);
header->rev = ntohl (header->rev);
header->entry = ntohl (header->entry);
header->data_start = ntohl (header->data_start);
header->data_end = ntohl (header->data_end);
header->bss_end = ntohl (header->bss_end);
header->stack_size = ntohl (header->stack_size);
header->reloc_start = ntohl (header->reloc_start);
header->reloc_count = ntohl (header->reloc_count);
header->flags = ntohl (header->flags);
return 0;
}
int flat_read_file_header(char *filename, struct flat_hdr *header)
{
FILE *fp;
int ret = 0;
if ((fp = fopen(filename, "r")) == NULL) {
return 1;
}
ret = flat_read_header(fp, header);
fclose(fp);
return ret;
}