* Move it into separate win32_snprintf.h file to de-duplicate its
implementation from all miniupnp source files.
* Do not use this emulation with mingw32 SDK when __NO_ISOCEXT is not
defined as in this case mingw32 provides working snprintf function.
* Fix detection for mingw-w64 variants, when __NO_ISOCEXT is defined or
when older version without UCRT is used.
* Add check if _scprintf function is available. In case it is not available
just returns length of filled buffer to prevent buffer overflow.
_snprintf() differs from snprintf() in:
* on overflow it returns -1 instead of required buffer size
* on overflow it does not fill nul byte
* does not accept NULL/0 as a buffer
Microsoft implemented snprintf() in Visual Studio 2015 as part of UCRT.
Mingw32 contains snprintf() implementation only when __USE_MINGW_ANSI_STDIO
is defined.
Mingw-w64 versions prior to 8.0.0. contain snprintf() implementation when
__USE_MINGW_ANSI_STDIO or _UCRT is defined. Since version 8.0.0 it is
always supported.
Mingw-w64 defines both __MINGW32__ and __MINGW64_VERSION_MAJOR macros.
Mingw32 defines only __MINGW32__.
_scprintf() just count number of bytes needed for formatting string, so it
is basically return value of snprintf().
This change updates miniupnpc code to use snprintf() when is provided by
compiler/runtime to avoid usage _snprintf().
And also this changes updates miniupnpc emulation of snprintf() by
_snprintf() and _scprintf() functions to avoid buffer overflows.
For inspiration full emulation of snprintf() by _snprintf() is available in
mingw-w64 stdio library:
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/stdio/snprintf.c
See https://github.com/miniupnp/miniupnp/issues/119
- Replace the sameport parameter to the upnpDiscover* functions
- Added constants UPNP_LOCAL_PORT_ANY(0) & UPNP_LOCAL_PORT_SAME(1). The
value "1" was chosen for presumed backwards compatability with the
previous "sameport" parameter (assuming usesr would have set to 1 if
they wanted same port)
- Can be specified with "-z" to the test programs "upnpc" & "pymoduletest.py"