-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.c
50 lines (34 loc) · 847 Bytes
/
converter.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
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
FILE *fp, *fp_out;
struct stat file_stat;
int size;
unsigned char *file;
int i, j, byte;
fp_out = fopen(argv[1], "w");
for(j = 2; j < argc; j++) {
i = j - 1;
stat(argv[j], &file_stat);
size = file_stat.st_size;
file = malloc(size);
if(file == NULL) {
printf("Faltou memoria\n");
return -1;
}
fp = fopen(argv[j], "rb");
fread(file, size, 1, fp);
fclose(fp);
fprintf(fp_out, "#define SIZE_FILE_%d %d\n", i,size);
fprintf(fp_out, "static const unsigned char rawData%d[SIZE_FILE_%d] = {\n", i, i);
fprintf(fp_out, "0x%xu", file[0]);
for (byte = 1; byte < size; byte++) {
fprintf(fp_out, ",0x%xu", file[byte]);
}
fprintf(fp_out, "\n};\n");
free(file);
}
fclose(fp_out);
return 0;
}