mdbx: snprintf/vsnprintf stub for MSC.

This commit is contained in:
Leo Yuriev 2017-04-04 15:17:24 +03:00
parent ab4597cedc
commit 6d507233cc
2 changed files with 16 additions and 4 deletions

View File

@ -97,7 +97,7 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) {
va_copy(ones, ap);
#ifdef _MSC_VER
int needed = _vscprintf(fmt, ap);
#elif defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
#elif defined(vsnprintf) || defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
int needed = vsnprintf(nullptr, 0, fmt, ap);
#else
@ -117,9 +117,7 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) {
return -ENOMEM;
}
#ifdef _MSC_VER
int actual = vsnprintf_s(*strp, needed + 1, _TRUNCATE, fmt, ones);
#elif defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
#if defined(vsnprintf) || defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
int actual = vsnprintf(*strp, needed + 1, fmt, ones);
#else

View File

@ -421,3 +421,17 @@ void mdbx_txn_unlock(MDB_env *env);
int mdbx_rpid_set(MDB_env *env);
int mdbx_rpid_clear(MDB_env *env);
int mdbx_rpid_check(MDB_env *env, mdbx_pid_t pid);
/*----------------------------------------------------------------------------*/
#ifdef _MSC_VER
#ifndef snprintf
#define snprintf(buffer, buffer_size, format, ...) \
_snprintf_s(buffer, buffer_size, _TRUNCATE, format, __VA_ARGS__)
#endif /* snprintf */
#ifndef vsnprintf
#define vsnprintf(buffer, buffer_size, format, args) \
_vsnprintf_s(buffer, buffer_size, _TRUNCATE, format, args)
#endif /* vsnprintf */
#endif /* _MSC_VER */