1 /* AbiSource Build Tools
2 * Copyright (C) 1998 AbiSource, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 long _getFileLength(const char* pszFileName)
27 FILE* fp = fopen(pszFileName, "rb");
33 if (0 != fseek(fp, 0, SEEK_END))
40 iLengthOfFile = ftell(fp);
47 long _readEntireFile(const char* pszFileName, unsigned char* pBytes, unsigned long iLen)
49 FILE* fp = fopen(pszFileName, "rb");
56 if (iLen != fread(pBytes, 1, iLen, fp))
68 void _dumpHexCBytes(FILE* fp, const unsigned char* pBytes, long iLen)
72 for (i=0; i<iLen; i++)
80 fprintf(fp, "0x%02x,", pBytes[i]);
86 int main(int argc, char** argv)
89 unsigned char* pBytes;
93 fprintf(stderr, "Usage: %s datafile arrayname\n", argv[0]);
98 iLen = _getFileLength(argv[1]);
99 pBytes = malloc(iLen);
101 _readEntireFile(argv[1], pBytes, iLen);
103 printf("unsigned char %s[] = {\n", argv[2]);
104 _dumpHexCBytes(stdout, pBytes, iLen);
107 printf("unsigned long %s_sizeof = sizeof(%s);\n",argv[2],argv[2]);