2
* GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS
3
* Copyright (C) 2007 Bean (bean123ch@gmail.com)
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
main (int argc, char *argv[])
31
fprintf (stderr, "Usage: bin2h file.dat outfile.h token_name\n");
35
in = fopen (argv[1], "rb");
39
fprintf (stderr, "bin2h: open %s fail\n", argv[1]);
43
fseek (in, 0, SEEK_END);
45
fseek (in, 0, SEEK_SET);
49
fprintf (stderr, "bin2h: %s is empty\n", argv[1]);
53
if ((data = malloc (length)) == NULL)
56
fprintf (stderr, "bin2h: can\'t allocate memory\n");
60
if ((fread (data, 1, length, in)) != length)
63
fprintf (stderr, "bin2h: read %s fail\n", argv[1]);
69
out = fopen (argv[2], "wt");
74
fprintf (stderr, "bin2h: open %s fail\n", argv[2]);
78
fprintf (out, "unsigned char %s[%d] = {", argv[3], length);
80
for (i = 0; i < length; i++)
86
fprintf (out, "%d", data[i]);
91
fprintf (out, "};\n");