mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
snprintf: unify fallback logic
Before this patch, the `snprintf()` fallback logic for envs not supporting this function (i.e. Visual Studio 2013 and older) varied depending on build tool, and used different techniques in examples, tests and libssh2 itself. This patch aims to apply a common logic to libssh2 and examples/tests. - libssh2: use local `snprintf()` fallback with all build tools. We already had a local implementation, but only with CMake. Move that to the library as `_libssh2_snprintf()`, and map `snprintf()` to it when `HAVE_SNPRINTF` is not set. Also change the length type from `int` to `size_t`, and fix formatting. - set or detect `HAVE_SNPRINTF` in non-CMake builds. Detect in autotools. Keep existing logic in `win32/libssh2_config.h`. Always set for OS/400, NetWare and VMS, keeping existing behaviour. (OS/400 builds use a different local implementation) - examples/tests: drop the CMake-specific fallback logic and map `snprintf()` to `_snprintf()` for old MSVC versions, like we did before with other build tools. This is unsafe, but should be fine for these uses. - `win32/libssh2_config.h`: make it easier to read. Closes #812
This commit is contained in:
@ -90,8 +90,6 @@ check_include_files(winsock2.h HAVE_WINSOCK2_H)
|
||||
|
||||
check_symbol_exists(strcasecmp strings.h HAVE_STRCASECMP)
|
||||
check_symbol_exists(_stricmp string.h HAVE__STRICMP)
|
||||
check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
|
||||
check_symbol_exists(_snprintf stdio.h HAVE__SNPRINTF)
|
||||
|
||||
check_symbol_exists(__func__ "" HAVE___FUNC__)
|
||||
check_symbol_exists(__FUNCTION__ "" HAVE___FUNCTION__)
|
||||
|
@ -48,8 +48,6 @@
|
||||
/* Functions */
|
||||
#cmakedefine HAVE_STRCASECMP
|
||||
#cmakedefine HAVE__STRICMP
|
||||
#cmakedefine HAVE_SNPRINTF
|
||||
#cmakedefine HAVE__SNPRINTF
|
||||
|
||||
/* Workaround for platforms without POSIX strcasecmp (e.g. Windows) */
|
||||
#ifndef HAVE_STRCASECMP
|
||||
|
@ -37,10 +37,8 @@
|
||||
#define INADDR_NONE (in_addr_t)~0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
# ifdef HAVE__SNPRINTF
|
||||
# define snprintf _snprintf
|
||||
# endif
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
const char *keyfile1 = "/home/username/.ssh/id_rsa.pub";
|
||||
|
Reference in New Issue
Block a user