]> git.ipfire.org Git - people/ms/strongswan.git/blame - scripts/bin2array.c
simple converter from binary data to a c array
[people/ms/strongswan.git] / scripts / bin2array.c
CommitLineData
68356ab1
MW
1
2#include <stdio.h>
3
4/**
5 * convert standard input to binary data to a c array
6 */
7int main(int argc, char *argv[])
8{
9 int i, end = 0;
10 char byte;
11
12 printf("char %s[] = {\n", argc > 1 ? argv[1] : "data");
13 while (1)
14 {
15 printf(" ");
16 for (i = 0; i < 16; i++)
17 {
18 if (fread(&byte, 1, 1, stdin) != 1)
19 {
20 end = 1;
21 break;
22 }
23 printf("0x%02x,", byte);
24 }
25 printf("\n");
26 if (end)
27 {
28 break;
29 }
30 }
31 printf("};\n");
32 return 0;
33}
34