summaryrefslogtreecommitdiffstats
path: root/util/bin-to-hex.c
blob: 48a71e75e418bdee46ec0cdf4211065bb5a77f8c (plain)
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
#include <stdio.h>

int main(int argc, char **argv)
{
	int c;
	int i;
	const char *name = argv[1];
	printf("#include <stddef.h>\n");
	printf("const char %s[] = {\n", name);
	i = 0;
	while((c = getchar()) != EOF) {
		if ((i % 16) != 0) {
			putchar(' ');
		}
		printf("0x%02x,", c);
		i++;
		if ((i %16) == 0) {
			putchar('\n');
		}
	}
	putchar('\n');
	printf("};\n");
	printf("size_t %s_size = sizeof(%s);\n", name, name);
	return 0;
}