Path: blob/master/thirdparty/miniupnpc/src/win32_snprintf.h
9904 views
/* vim: tabstop=4 shiftwidth=4 noexpandtab1* MiniUPnP project2* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/3* (c) 2020 Pali Rohár4* This software is subject to the conditions detailed5* in the LICENCE file provided within the distribution */67#ifndef WIN32_SNPRINTF_H8#define WIN32_SNPRINTF_H910#ifdef _WIN321112#include <stdio.h>1314/* snprintf is supported by:15* - Visual Studio 2015 or new16* - mingw32 with iso c ext17* - mingw-w64 with ansi stdio18* - mingw-w64 6.0.0 or new with ucrt19* - mingw-w64 8.0.0 or new with iso c ext20*/21#if ( \22(defined(_MSC_VER) && _MSC_VER < 1900) /* Visual Studio older than 2015 */ || \23(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) && defined(__NO_ISOCEXT)) /* mingw32 without iso c ext */ || \24(defined(__MINGW64_VERSION_MAJOR) && /* mingw-w64 not ... */ !( \25(defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO != 0) /* ... with ansi stdio */ || \26(__MINGW64_VERSION_MAJOR >= 6 && defined(_UCRT)) /* ... at least 6.0.0 with ucrt */ || \27(__MINGW64_VERSION_MAJOR >= 8 && !defined(__NO_ISOCEXT))) /* ... at least 8.0.0 with iso c ext */ || \280) || \290)3031/* _scprintf is supported by:32* - Visual Studio 2002 or new33* - msvcr70.dll or new34* - msvcrt.dll on Windows XP or new35*/36#if ( \37(defined(_MSC_VER) && _MSC_VER < 1300) /* Visual Studio older than 2002 */ || \38(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x700) /* msvcrt older than 7.0 */ || \390)40#define CHECK_SCPRINTF 041#define IF_SCPRINTF(expr) 042#define ELSE_SCPRINTF(expr) expr43#else44#define CHECK_SCPRINTF 145#define IF_SCPRINTF(expr) expr46#define ELSE_SCPRINTF(expr) 047#endif4849/* Emulation of snprintf for win32 */50#define snprintf(buf, size, fmt, ...) ( \51(((size) != 0 && (buf) != NULL) ? ( /* _snprintf does not work with NULL buffer */ \52_snprintf((buf), (size), (fmt), __VA_ARGS__), /* _snprintf returns -1 on overflow, so ignore its value */ \53(((char *)buf)[(size_t)(size)-1] = 0), /* _snprintf does not fill nul byte on overflow */ \540) : 0), \55(CHECK_SCPRINTF ? IF_SCPRINTF( \56_scprintf((fmt), __VA_ARGS__) /* calculate return value for snprintf via _scprintf */ \57) : ELSE_SCPRINTF( \58((size) != 0 && (buf) != NULL) ? \59strlen((buf)) /* return just length of buffer */ \60: \611 /* no buffer, impossible to calculate, return just non-zero number */ \62) \63) \64)6566#endif6768#endif /* _WIN32 */6970#endif /* WIN32_SNPRINTF_H */717273