]>
Commit | Line | Data |
---|---|---|
0a823aa2 HW |
1 | /* bin2header.c - program to convert binary file into a C structure |
2 | * definition to be included in a header file. | |
3 | * | |
4 | * (C) Copyright 2008 by Harald Welte <[email protected]> | |
5 | * | |
1a459660 | 6 | * SPDX-License-Identifier: GPL-2.0+ |
0a823aa2 HW |
7 | */ |
8 | ||
9 | #include <stdlib.h> | |
10 | #include <stdio.h> | |
8a7367ac | 11 | #include <unistd.h> |
0a823aa2 HW |
12 | |
13 | int main(int argc, char **argv) | |
14 | { | |
15 | if (argc < 2) { | |
16 | fprintf(stderr, "%s needs one argument: the structure name\n", | |
17 | argv[0]); | |
18 | exit(1); | |
19 | } | |
20 | ||
21 | printf("/* bin2header output - automatically generated */\n"); | |
22 | printf("unsigned char %s[] = {\n", argv[1]); | |
23 | ||
24 | while (1) { | |
25 | int i, nread; | |
26 | unsigned char buf[10]; | |
27 | nread = read(0, buf, sizeof(buf)); | |
28 | if (nread <= 0) | |
29 | break; | |
30 | ||
31 | printf("\t"); | |
32 | for (i = 0; i < nread - 1; i++) | |
33 | printf("0x%02x, ", buf[i]); | |
34 | ||
35 | printf("0x%02x,\n", buf[nread-1]); | |
36 | } | |
37 | ||
38 | printf("};\n"); | |
39 | ||
40 | exit(0); | |
41 | } |