blob: 27a5b6aab6ecbac10bc866312bd03c5957b6188c [file] [log] [blame]
Harald Welte0a823aa2008-07-09 22:30:30 +08001/* 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 <laforge@openmoko.org>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Harald Welte0a823aa2008-07-09 22:30:30 +08007 */
8
9#include <stdlib.h>
10#include <stdio.h>
11
12int main(int argc, char **argv)
13{
14 if (argc < 2) {
15 fprintf(stderr, "%s needs one argument: the structure name\n",
16 argv[0]);
17 exit(1);
18 }
19
20 printf("/* bin2header output - automatically generated */\n");
21 printf("unsigned char %s[] = {\n", argv[1]);
22
23 while (1) {
24 int i, nread;
25 unsigned char buf[10];
26 nread = read(0, buf, sizeof(buf));
27 if (nread <= 0)
28 break;
29
30 printf("\t");
31 for (i = 0; i < nread - 1; i++)
32 printf("0x%02x, ", buf[i]);
33
34 printf("0x%02x,\n", buf[nread-1]);
35 }
36
37 printf("};\n");
38
39 exit(0);
40}