mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 22:44:14 +08:00
mdbx-windows: refine mdbx_vasprintf() to avoid dependency from CRT.
10 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43 Change-Id: I95c4583c27503eb4e9221b212b34474dfb561e6d
This commit is contained in:
parent
80ccb31008
commit
f49741b4f8
12
src/osal.c
12
src/osal.c
@ -219,14 +219,7 @@ __cold void mdbx_panic(const char *fmt, ...) {
|
|||||||
int mdbx_vasprintf(char **strp, const char *fmt, va_list ap) {
|
int mdbx_vasprintf(char **strp, const char *fmt, va_list ap) {
|
||||||
va_list ones;
|
va_list ones;
|
||||||
va_copy(ones, ap);
|
va_copy(ones, ap);
|
||||||
#ifdef _MSC_VER
|
|
||||||
int needed = _vscprintf(fmt, ap);
|
|
||||||
#elif defined(vsnprintf) || defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
|
|
||||||
defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
|
|
||||||
int needed = vsnprintf(nullptr, 0, fmt, ap);
|
int needed = vsnprintf(nullptr, 0, fmt, ap);
|
||||||
#else
|
|
||||||
#error FIXME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (unlikely(needed < 0 || needed >= INT_MAX)) {
|
if (unlikely(needed < 0 || needed >= INT_MAX)) {
|
||||||
*strp = nullptr;
|
*strp = nullptr;
|
||||||
@ -245,12 +238,7 @@ int mdbx_vasprintf(char **strp, const char *fmt, va_list ap) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(vsnprintf) || defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || \
|
|
||||||
defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
|
|
||||||
int actual = vsnprintf(*strp, needed + 1, fmt, ones);
|
int actual = vsnprintf(*strp, needed + 1, fmt, ones);
|
||||||
#else
|
|
||||||
#error FIXME
|
|
||||||
#endif
|
|
||||||
va_end(ones);
|
va_end(ones);
|
||||||
|
|
||||||
assert(actual == needed);
|
assert(actual == needed);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user