and a fix for it
[strongswan.git] / scripts / bin2array.c
1
2 #include <stdio.h>
3
4 /**
5 * convert standard input to binary data to a c array
6 */
7 int main(int argc, char *argv[])
8 {
9 int i, end = 0;
10 unsigned 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,", (unsigned int)byte);
24 }
25 printf("\n");
26 if (end)
27 {
28 break;
29 }
30 }
31 printf("};\n");
32 return 0;
33 }
34