reactos/sdk/tools/bin2c.c
Joachim Henze 810543987d [0.4.11][HOST-TOOLS] Fix all remaining (>78) MSVC2010SP1 x86 dbg warnings C4018,C4996,... CORE-18104 (#1525)
From releases/0.4.9 to releases/0.4.10 we introduced tons of compiler warnings
within the whole host-tools component although the 'offending' code did not change in between both.
I am not aware which commit unhid them exactly during 0.4.10-dev',
but I will follow the footsteps of master with the fixes.
releases/0.4.9 still had 0 warnings within host-tools, and releases/0.4.13 managed to achieve the same again!

fix is a pick from:
0.4.13-dev-132-g f47f45dbdd (picked the remaining parts of that)
0.4.13-dev-133-g c02257ef57
0.4.13-dev-134-g 2c11c41115

the warnings could be observed with MSVC 2010SP1 (16.0.40219.1) x86 target in dbg configuration:

where the
0.4.13-dev-132-g f47f45dbdd part fixed the:

[6/12736] Performing build step for 'host-tools'
[13/250] Building CXX object sdk\tools\hhpcomp\CMakeFiles\hhpcomp.dir\hhpcomp.cpp.obj
C:\0410rls\reactos\sdk\tools\hhpcomp\hhpcomp.cpp(59) : warning C4996: 'chdir': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _chdir. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\direct.h(123) : see declaration of 'chdir'
C:\0410rls\reactos\sdk\tools\hhpcomp\chmc\chmc.c(160) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\hhpcomp\chmc\chmc.c(447) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\hhpcomp\chmc\chmc.c(476) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\hhpcomp\chmc\chmc.c(511) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\hpp\hpp.c(44) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\isohybrid\isohybrid.c(1201) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\isohybrid\isohybrid.c(1204) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\kbdtool\parser.c(448) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\kbdtool\parser.c(523) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\kbdtool\parser.c(598) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\stdio\ffileread.c(30) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\stdio\fcons.c(62) : warning C4996: 'fdopen': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fdopen. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(721) : see declaration of 'fdopen'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\stdio\flag.c(44) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\stdio\flag.c(73) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\stdio\flag.c(98) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\stdio\filewrite.c(82) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\fconv.c(231) : warning C4996: 'ecvt': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _ecvt. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdlib.h(864) : see declaration of 'ecvt'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\fconv.c(320) : warning C4996: 'fcvt': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fcvt. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdlib.h(865) : see declaration of 'fcvt'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\format.c(745) : warning C4996: 'gcvt': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _gcvt. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdlib.h(866) : see declaration of 'gcvt'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libschily\searchinpath.c(221) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\libsiconv\sic_nls.c(450) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(169) : warning C4996: 'access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(299) : see declaration of 'access'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(225) : warning C4996: 'access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(299) : see declaration of 'access'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(414) : warning C4996: 'open': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _open. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(312) : see declaration of 'open'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(420) : warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(313) : see declaration of 'read'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(425) : warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _close. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(302) : see declaration of 'close'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(464) : warning C4996: 'open': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _open. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(312) : see declaration of 'open'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(467) : warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(313) : see declaration of 'read'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(469) : warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _close. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(302) : see declaration of 'close'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(536) : warning C4996: 'open': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _open. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(312) : see declaration of 'open'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(541) : warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(313) : see declaration of 'read'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\boot.c(549) : warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _close. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(302) : see declaration of 'close'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(447) : warning C4996: 'open': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _open. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(312) : see declaration of 'open'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(453) : warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(313) : see declaration of 'read'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(457) : warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _close. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(302) : see declaration of 'close'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(585) : warning C4996: 'open': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _open. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(312) : see declaration of 'open'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(594) : warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(313) : see declaration of 'read'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(615) : warning C4996: 'lseek': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _lseek. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(310) : see declaration of 'lseek'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(623) : warning C4996: 'write': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _write. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(318) : see declaration of 'write'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\eltorito.c(624) : warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _close. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(302) : see declaration of 'close'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\match.c(74) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\match.c(201) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\multi.c(124) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\multi.c(126) : warning C4996: 'lseek': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _lseek. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(310) : see declaration of 'lseek'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\multi.c(130) : warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(313) : see declaration of 'read'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\multi.c(124) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(723) : see declaration of 'fileno'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\multi.c(126) : warning C4996: 'lseek': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _lseek. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(310) : see declaration of 'lseek'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\multi.c(130) : warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(313) : see declaration of 'read'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\tree.c(1628) : warning C4996: 'access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\io.h(299) : see declaration of 'access'
C:\0410rls\reactos\sdk\tools\mkisofs\schilytools\mkisofs\write.c(204) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'

C:\0410rls\reactos\sdk\tools\wpp\preproc.c(162) : warning C4013: 'open' undefined; assuming extern returning int
C:\0410rls\reactos\sdk\tools\wpp\preproc.c(165) : warning C4013: 'close' undefined; assuming extern returning int

C:\0410rls\reactos\sdk\tools\widl\widl.c(863) : warning C4996: 'fdopen': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fdopen. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(721) : see declaration of 'fdopen'
C:\0410rls\reactos\sdk\tools\widl\widl.c(910) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(912) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(914) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(916) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(918) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(920) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(922) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(924) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
C:\0410rls\reactos\sdk\tools\widl\widl.c(926) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'

C:\0410rls\reactos\sdk\tools\widl\typelib.c(264) : warning C4013: 'read' undefined; assuming extern returning int
C:\0410rls\reactos\sdk\tools\widl\typelib.c(270) : warning C4013: 'lseek' undefined; assuming extern returning int
C:\0410rls\reactos\sdk\tools\widl\typelib.c(343) : warning C4013: 'open' undefined; assuming extern returning int
C:\0410rls\reactos\sdk\tools\widl\typelib.c(383) : warning C4013: 'close' undefined; assuming extern returning int

C:\0410rls\reactos\sdk\tools\widl\utils.c(281) : warning C4013: 'open' undefined; assuming extern returning int
C:\0410rls\reactos\sdk\tools\widl\utils.c(283) : warning C4013: 'write' undefined; assuming extern returning int
C:\0410rls\reactos\sdk\tools\widl\utils.c(285) : warning C4013: 'close' undefined; assuming extern returning int

[194/250] Building C object sdk\tools\widl\CMakeFiles\widl.dir\parser.yy.c.obj
parser.l(488) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'
parser.l(542) : warning C4996: 'fdopen': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fdopen. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(721) : see declaration of 'fdopen'
parser.l(562) : warning C4996: 'unlink': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\stdio.h(299) : see declaration of 'unlink'

[197/250] Building C object sdk\tools\widl\CMakeFiles\widl.dir\parser.tab.c.obj
parser.y(454) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
        C:\VS2010_SP1\VC\INCLUDE\string.h(238) : see declaration of 'strdup'

... and so on ... too many to name them all
----------
0.4.13-dev-134-g 2c11c41115 part fixed the:
C:\0410rls\reactos\sdk\tools\widl\getopt.c(233) : warning C4013: '_getopt_internal' undefined; assuming extern returning int
----------
0.4.13-dev-133-g c02257ef57 part fixed the:
C:\0410rls\reactos\sdk\tools\isohybrid\isohybrid.c(978) : warning C4101: 'orig_gpt_size' : unreferenced local variable
C:\0410rls\reactos\sdk\tools\isohybrid\isohybrid.c(978) : warning C4101: 'gpt_size' : unreferenced local variable
2022-09-17 21:55:43 +02:00

181 lines
4.6 KiB
C

/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS bin2c
* FILE: tools/bin2c.c
* PURPOSE: Converts a binary file into a byte array
* PROGRAMMER: Hermès Bélusca - Maïto
*/
#include <stdio.h>
#ifdef _WIN32
#include <string.h> // Required for _stricmp()
#else
#include <strings.h> // Required for strcasecmp()
#define _stricmp strcasecmp
#endif
static size_t dumpHex(FILE* inFile, FILE* outCFile, char nullTerminate)
{
size_t bufLen = 0;
unsigned char ch;
fprintf(outCFile, "\n{");
do
{
/* Read the next byte */
ch = fgetc(inFile);
if (feof(inFile) && nullTerminate)
ch = 0x00;
if (!feof(inFile) || nullTerminate)
{
/* Start a new line if needed */
if ((bufLen % 16) == 0)
fprintf(outCFile, "\n ");
/* Write the byte or the optional NULL terminator */
fprintf(outCFile, " 0x%02x,", (unsigned int)ch);
++bufLen;
}
} while (!feof(inFile));
fprintf(outCFile, "\n}");
return bufLen;
}
static size_t dumpStr(FILE* inFile, FILE* outCFile)
{
size_t bufLen = 0;
unsigned char ch;
/* Always start the first line */
fprintf(outCFile, "\n \"");
do
{
/* Read the next byte */
ch = fgetc(inFile);
/* If a byte is available... */
if (!feof(inFile))
{
/* ... do we need to start a new line? */
if ((bufLen != 0) && (bufLen % 16) == 0)
{
/* Yes, end the current line and start a new one */
fprintf(outCFile, "\"");
fprintf(outCFile, "\n \"");
}
/* Now write the byte */
fprintf(outCFile, "\\x%02x", (unsigned int)ch);
}
/* ... otherwise, end the current line... */
else
{
fprintf(outCFile, "\"");
/* We break just after */
}
++bufLen; // This takes also the final NULL terminator into account.
} while (!feof(inFile));
return bufLen;
}
static void usage(char* name)
{
fprintf(stdout, "Usage: %s infile.bin outfile.c outfile.h [BIN|BINSTR|STR] array_name [array_attribute [header_for_attribute]]\n", name);
}
int main(int argc, char* argv[])
{
FILE* inFile;
FILE* outCFile;
FILE* outHFile;
size_t bufLen;
/* Validate the arguments */
if (argc < 6)
{
usage(argv[0]);
return -1;
}
/* Verify the output format */
if (_stricmp(argv[4], "BIN" ) != 0 &&
_stricmp(argv[4], "BINSTR") != 0 &&
_stricmp(argv[4], "STR" ) != 0)
{
usage(argv[0]);
return -1;
}
/* Open the input and output files */
inFile = fopen(argv[1], "rb");
if (!inFile)
{
fprintf(stderr, "ERROR: Couldn't open data file '%s'.\n", argv[1]);
return -1;
}
outCFile = fopen(argv[2], "w");
if (!outCFile)
{
fclose(inFile);
fprintf(stderr, "ERROR: Couldn't create output source file '%s'.\n", argv[2]);
return -1;
}
outHFile = fopen(argv[3], "w");
if (!outHFile)
{
fclose(outCFile);
fclose(inFile);
fprintf(stderr, "ERROR: Couldn't create output header file '%s'.\n", argv[3]);
return -1;
}
/* Generate the source file and close it */
fprintf(outCFile, "/* This file is autogenerated, do not edit. */\n\n");
if (argc >= 8)
{
/* Include needed header for defining the array attribute */
fprintf(outCFile, "#include \"%s\"\n", argv[7]);
}
fprintf(outCFile, "#include \"%s\"\n\n", argv[3]);
/* Generate the data array */
if (argc >= 7)
{
/* Add the array attribute */
fprintf(outCFile, "%s ", argv[6]);
}
fprintf(outCFile, "unsigned char %s[] =", argv[5]);
/* Output the bytes in the chosen format */
if (_stricmp(argv[4], "BIN") == 0)
bufLen = dumpHex(inFile, outCFile, 0);
else if (_stricmp(argv[4], "BINSTR") == 0)
bufLen = dumpHex(inFile, outCFile, 1);
else // (_stricmp(argv[4], "STR") == 0)
bufLen = dumpStr(inFile, outCFile);
fprintf(outCFile, ";\n");
fclose(outCFile);
/* Generate the header file and close it */
fprintf(outHFile, "/* This file is autogenerated, do not edit. */\n\n");
fprintf(outHFile, "#define %s_SIZE %lu\n" , argv[5], (unsigned long)bufLen);
fprintf(outHFile, "extern unsigned char %s[%lu];\n", argv[5], (unsigned long)bufLen);
fclose(outHFile);
/* Close the input file */
fclose(inFile);
return 0;
}
/* EOF */