From 6d507233cc9e7fb04bca9b714a30f4d9fc9d6661 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Tue, 4 Apr 2017 15:17:24 +0300 Subject: [PATCH] mdbx: snprintf/vsnprintf stub for MSC. --- src/osal.c | 6 ++---- src/osal.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/osal.c b/src/osal.c index 7061204a..2bac64e1 100644 --- a/src/osal.c +++ b/src/osal.c @@ -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 diff --git a/src/osal.h b/src/osal.h index 469ca341..4000475b 100644 --- a/src/osal.h +++ b/src/osal.h @@ -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 */