reactos/sdk/lib/inflib/infget.c
Joachim Henze b2494542da [0.4.10][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.11-dev-436-g da019b0fc5 (the mkhive\registry.c part)
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
----------
partial port (registry.c) of 0.4.11-dev-436-g da019b0fc5 fixed the:
C:\0410rls\reactos\sdk\tools\mkhive\registry.c(369) : warning C4101: 'SubKeyCell' : unreferenced local variable
2022-09-17 22:00:33 +02:00

679 lines
16 KiB
C

/*
* PROJECT: .inf file parser
* LICENSE: GPL - See COPYING in the top level directory
* PROGRAMMER: Royce Mitchell III
* Eric Kohl
* Ge van Geldorp <gvg@reactos.org>
*/
/* INCLUDES *****************************************************************/
#include "inflib.h"
#define NDEBUG
#include <debug.h>
static size_t
InfpSubstituteString(PINFCACHE Inf,
const WCHAR *text,
WCHAR *buffer,
size_t size);
static void
ShortToHex(PWCHAR Buffer,
USHORT Value)
{
WCHAR HexDigits[] = L"0123456789abcdef";
Buffer[0] = HexDigits[Value >> 12 & 0xf];
Buffer[1] = HexDigits[Value >> 8 & 0xf];
Buffer[2] = HexDigits[Value >> 4 & 0xf];
Buffer[3] = HexDigits[Value >> 0 & 0xf];
}
/* retrieve the string substitution for a given string, or NULL if not found */
/* if found, len is set to the substitution length */
static PCWSTR
InfpGetSubstitutionString(PINFCACHE Inf,
PCWSTR str,
size_t *len,
BOOL no_trailing_slash)
{
static const WCHAR percent = '%';
INFSTATUS Status = INF_STATUS_NOT_FOUND;
PINFCONTEXT Context = NULL;
PWCHAR Data = NULL;
WCHAR ValueName[MAX_INF_STRING_LENGTH +1];
WCHAR StringLangId[] = L"Strings.XXXX";
if (!*len) /* empty string (%%) is replaced by single percent */
{
*len = 1;
return &percent;
}
memcpy(ValueName, str, *len * sizeof(WCHAR));
ValueName[*len] = 0;
DPRINT("Value name: %S\n", ValueName);
if (Inf->LanguageId != 0)
{
ShortToHex(&StringLangId[sizeof("Strings.") - 1],
Inf->LanguageId);
Status = InfpFindFirstLine(Inf,
StringLangId,
ValueName,
&Context);
if (Status != INF_STATUS_SUCCESS)
{
ShortToHex(&StringLangId[sizeof("Strings.") - 1],
MAKELANGID(PRIMARYLANGID(Inf->LanguageId), SUBLANG_NEUTRAL));
Status = InfpFindFirstLine(Inf,
StringLangId,
ValueName,
&Context);
if (Status != INF_STATUS_SUCCESS)
{
Status = InfpFindFirstLine(Inf,
L"Strings",
ValueName,
&Context);
}
}
}
else
{
Status = InfpFindFirstLine(Inf,
L"Strings",
ValueName,
&Context);
}
if (Status != INF_STATUS_SUCCESS || Context == NULL)
return NULL;
Status = InfpGetData(Context,
NULL,
&Data);
InfpFreeContext(Context);
if (Status == STATUS_SUCCESS)
{
*len = strlenW(Data);
DPRINT("Substitute: %S Length: %zu\n", Data, *len);
return Data;
}
return NULL;
}
/* do string substitutions on the specified text */
/* the buffer is assumed to be large enough */
/* returns necessary length not including terminating null */
static size_t
InfpSubstituteString(PINFCACHE Inf,
PCWSTR text,
PWSTR buffer,
size_t size)
{
const WCHAR *start, *subst, *p;
size_t len, total = 0;
int inside = 0;
if (!buffer) size = MAX_INF_STRING_LENGTH + 1;
for (p = start = text; *p; p++)
{
if (*p != '%') continue;
inside = !inside;
if (inside) /* start of a %xx% string */
{
len = (p - start);
if (len > size - 1) len = size - 1;
if (buffer) memcpy( buffer + total, start, len * sizeof(WCHAR) );
total += len;
size -= len;
start = p;
}
else /* end of the %xx% string, find substitution */
{
len = (p - start - 1);
subst = InfpGetSubstitutionString( Inf, start + 1, &len, p[1] == '\\' );
if (!subst)
{
subst = start;
len = (p - start + 1);
}
if (len > size - 1) len = size - 1;
if (buffer) memcpy( buffer + total, subst, len * sizeof(WCHAR) );
total += len;
size -= len;
start = p + 1;
}
}
if (start != p) /* unfinished string, copy it */
{
len = (unsigned int)(p - start);
if (len > size - 1) len = size - 1;
if (buffer) memcpy( buffer + total, start, len * sizeof(WCHAR) );
total += len;
}
if (buffer && size) buffer[total] = 0;
return total;
}
INFSTATUS
InfpFindFirstLine(PINFCACHE Cache,
PCWSTR Section,
PCWSTR Key,
PINFCONTEXT *Context)
{
PINFCACHESECTION CacheSection;
PINFCACHELINE CacheLine;
if (Cache == NULL || Section == NULL || Context == NULL)
{
DPRINT1("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
CacheSection = InfpFindSection(Cache, Section);
if (NULL == CacheSection)
{
DPRINT("Section not found\n");
return INF_STATUS_NOT_FOUND;
}
if (Key != NULL)
{
CacheLine = InfpFindKeyLine(CacheSection, Key);
}
else
{
CacheLine = CacheSection->FirstLine;
}
if (NULL == CacheLine)
{
DPRINT("Key not found\n");
return INF_STATUS_NOT_FOUND;
}
*Context = MALLOC(sizeof(INFCONTEXT));
if (NULL == *Context)
{
DPRINT1("MALLOC() failed\n");
return INF_STATUS_NO_MEMORY;
}
(*Context)->Inf = (PVOID)Cache;
(*Context)->Section = (PVOID)CacheSection;
(*Context)->Line = (PVOID)CacheLine;
return INF_STATUS_SUCCESS;
}
INFSTATUS
InfpFindNextLine(PINFCONTEXT ContextIn,
PINFCONTEXT ContextOut)
{
PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL)
return INF_STATUS_INVALID_PARAMETER;
if (ContextIn->Line == NULL)
return INF_STATUS_INVALID_PARAMETER;
CacheLine = (PINFCACHELINE)ContextIn->Line;
if (CacheLine->Next == NULL)
return INF_STATUS_NOT_FOUND;
if (ContextIn != ContextOut)
{
ContextOut->Inf = ContextIn->Inf;
ContextOut->Section = ContextIn->Section;
}
ContextOut->Line = (PVOID)(CacheLine->Next);
return INF_STATUS_SUCCESS;
}
INFSTATUS
InfpFindFirstMatchLine(PINFCONTEXT ContextIn,
PCWSTR Key,
PINFCONTEXT ContextOut)
{
PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0)
return INF_STATUS_INVALID_PARAMETER;
if (ContextIn->Inf == NULL || ContextIn->Section == NULL)
return INF_STATUS_INVALID_PARAMETER;
CacheLine = ((PINFCACHESECTION)(ContextIn->Section))->FirstLine;
while (CacheLine != NULL)
{
if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0)
{
if (ContextIn != ContextOut)
{
ContextOut->Inf = ContextIn->Inf;
ContextOut->Section = ContextIn->Section;
}
ContextOut->Line = (PVOID)CacheLine;
return INF_STATUS_SUCCESS;
}
CacheLine = CacheLine->Next;
}
return INF_STATUS_NOT_FOUND;
}
INFSTATUS
InfpFindNextMatchLine(PINFCONTEXT ContextIn,
PCWSTR Key,
PINFCONTEXT ContextOut)
{
PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0)
return INF_STATUS_INVALID_PARAMETER;
if (ContextIn->Inf == NULL || ContextIn->Section == NULL || ContextIn->Line == NULL)
return INF_STATUS_INVALID_PARAMETER;
CacheLine = (PINFCACHELINE)ContextIn->Line;
while (CacheLine != NULL)
{
if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0)
{
if (ContextIn != ContextOut)
{
ContextOut->Inf = ContextIn->Inf;
ContextOut->Section = ContextIn->Section;
}
ContextOut->Line = (PVOID)CacheLine;
return INF_STATUS_SUCCESS;
}
CacheLine = CacheLine->Next;
}
return INF_STATUS_NOT_FOUND;
}
LONG
InfpGetLineCount(HINF InfHandle,
PCWSTR Section)
{
PINFCACHE Cache;
PINFCACHESECTION CacheSection;
if (InfHandle == NULL || Section == NULL)
{
DPRINT("Invalid parameter\n");
return -1;
}
Cache = (PINFCACHE)InfHandle;
/* Iterate through list of sections */
CacheSection = Cache->FirstSection;
while (CacheSection != NULL)
{
/* Are the section names the same? */
if (strcmpiW(CacheSection->Name, Section) == 0)
{
return CacheSection->LineCount;
}
/* Get the next section */
CacheSection = CacheSection->Next;
}
DPRINT("Section not found\n");
return -1;
}
/* InfpGetLineText */
LONG
InfpGetFieldCount(PINFCONTEXT Context)
{
if (Context == NULL || Context->Line == NULL)
return 0;
return ((PINFCACHELINE)Context->Line)->FieldCount;
}
INFSTATUS
InfpGetBinaryField(PINFCONTEXT Context,
ULONG FieldIndex,
PUCHAR ReturnBuffer,
ULONG ReturnBufferSize,
PULONG RequiredSize)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
ULONG Size;
PUCHAR Ptr;
if (Context == NULL || Context->Line == NULL || FieldIndex == 0)
{
DPRINT("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
if (RequiredSize != NULL)
*RequiredSize = 0;
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > (ULONG)CacheLine->FieldCount)
return INF_STATUS_NOT_FOUND;
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
Size = (ULONG)CacheLine->FieldCount - FieldIndex + 1;
if (RequiredSize != NULL)
*RequiredSize = Size;
if (ReturnBuffer != NULL)
{
if (ReturnBufferSize < Size)
return INF_STATUS_BUFFER_OVERFLOW;
/* Copy binary data */
Ptr = ReturnBuffer;
while (CacheField != NULL)
{
*Ptr = (UCHAR)strtoulW(CacheField->Data, NULL, 16);
Ptr++;
CacheField = CacheField->Next;
}
}
return INF_STATUS_SUCCESS;
}
INFSTATUS
InfpGetIntField(PINFCONTEXT Context,
ULONG FieldIndex,
INT *IntegerValue)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
PWCHAR Ptr;
if (Context == NULL || Context->Line == NULL || IntegerValue == NULL)
{
DPRINT("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > (ULONG)CacheLine->FieldCount)
{
DPRINT("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
if (FieldIndex == 0)
{
Ptr = CacheLine->Key;
}
else
{
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
Ptr = CacheField->Data;
}
*IntegerValue = (LONG)strtolW(Ptr, NULL, 0);
return INF_STATUS_SUCCESS;
}
INFSTATUS
InfpGetMultiSzField(PINFCONTEXT Context,
ULONG FieldIndex,
PWSTR ReturnBuffer,
ULONG ReturnBufferSize,
PULONG RequiredSize)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
PINFCACHEFIELD FieldPtr;
ULONG Index;
ULONG Size;
PWCHAR Ptr;
if (Context == NULL || Context->Line == NULL || FieldIndex == 0)
{
DPRINT("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
if (RequiredSize != NULL)
*RequiredSize = 0;
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > (ULONG)CacheLine->FieldCount)
return INF_STATUS_INVALID_PARAMETER;
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
/* Calculate the required buffer size */
FieldPtr = CacheField;
Size = 0;
while (FieldPtr != NULL)
{
Size += ((ULONG)strlenW(FieldPtr->Data) + 1);
FieldPtr = FieldPtr->Next;
}
Size++;
if (RequiredSize != NULL)
*RequiredSize = Size;
if (ReturnBuffer != NULL)
{
if (ReturnBufferSize < Size)
return INF_STATUS_BUFFER_OVERFLOW;
/* Copy multi-sz string */
Ptr = ReturnBuffer;
FieldPtr = CacheField;
while (FieldPtr != NULL)
{
Size = (ULONG)strlenW(FieldPtr->Data) + 1;
strcpyW(Ptr, FieldPtr->Data);
Ptr = Ptr + Size;
FieldPtr = FieldPtr->Next;
}
*Ptr = 0;
}
return INF_STATUS_SUCCESS;
}
INFSTATUS
InfpGetStringField(PINFCONTEXT Context,
ULONG FieldIndex,
PWSTR ReturnBuffer,
ULONG ReturnBufferSize,
PULONG RequiredSize)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
PWCHAR Ptr;
SIZE_T Size;
if (Context == NULL || Context->Line == NULL)
{
DPRINT("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
if (RequiredSize != NULL)
*RequiredSize = 0;
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > (ULONG)CacheLine->FieldCount)
return INF_STATUS_INVALID_PARAMETER;
if (FieldIndex == 0)
{
Ptr = CacheLine->Key;
}
else
{
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
Ptr = CacheField->Data;
}
// Size = (ULONG)strlenW(Ptr) + 1;
Size = InfpSubstituteString(Context->Inf,
Ptr,
NULL,
0);
if (RequiredSize != NULL)
*RequiredSize = (ULONG)Size + 1;
if (ReturnBuffer != NULL)
{
if (ReturnBufferSize <= Size)
return INF_STATUS_BUFFER_OVERFLOW;
// strcpyW(ReturnBuffer, Ptr);
InfpSubstituteString(Context->Inf,
Ptr,
ReturnBuffer,
ReturnBufferSize);
}
return INF_STATUS_SUCCESS;
}
INFSTATUS
InfpGetData(PINFCONTEXT Context,
PWCHAR *Key,
PWCHAR *Data)
{
PINFCACHELINE CacheKey;
if (Context == NULL || Context->Line == NULL || Data == NULL)
{
DPRINT("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
CacheKey = (PINFCACHELINE)Context->Line;
if (Key != NULL)
*Key = CacheKey->Key;
if (Data != NULL)
{
if (CacheKey->FirstField == NULL)
{
*Data = NULL;
}
else
{
*Data = CacheKey->FirstField->Data;
}
}
return INF_STATUS_SUCCESS;
}
INFSTATUS
InfpGetDataField(PINFCONTEXT Context,
ULONG FieldIndex,
PWCHAR *Data)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
if (Context == NULL || Context->Line == NULL || Data == NULL)
{
DPRINT("Invalid parameter\n");
return INF_STATUS_INVALID_PARAMETER;
}
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > (ULONG)CacheLine->FieldCount)
return INF_STATUS_INVALID_PARAMETER;
if (FieldIndex == 0)
{
*Data = CacheLine->Key;
}
else
{
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
*Data = CacheField->Data;
}
return INF_STATUS_SUCCESS;
}
VOID
InfpFreeContext(PINFCONTEXT Context)
{
FREE(Context);
}
/* EOF */