From 6317706b03b32c4ca7019725bfe2df232063c786 Mon Sep 17 00:00:00 2001 From: terminx Date: Fri, 20 Sep 2019 06:42:42 +0000 Subject: [PATCH] Derp git-svn-id: https://svn.eduke32.com/eduke32@8133 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/libxmp-lite/src/win32.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 source/libxmp-lite/src/win32.c diff --git a/source/libxmp-lite/src/win32.c b/source/libxmp-lite/src/win32.c new file mode 100644 index 000000000..3844565ac --- /dev/null +++ b/source/libxmp-lite/src/win32.c @@ -0,0 +1,34 @@ +/* _[v]snprintf() from msvcrt.dll might not nul terminate */ +/* OpenWatcom-provided versions seem to behave the same... */ + +#if defined(_WIN32) || defined(__WATCOMC__) + +#include +#include + +#undef snprintf +#undef vsnprintf + +int libxmp_vsnprintf(char *str, size_t sz, const char *fmt, va_list ap) +{ + int rc = _vsnprintf(str, sz, fmt, ap); + if (sz != 0) { + if (rc < 0) rc = (int)sz; + if ((size_t)rc >= sz) str[sz - 1] = '\0'; + } + return rc; +} + +int libxmp_snprintf (char *str, size_t sz, const char *fmt, ...) +{ + va_list ap; + int rc; + + va_start (ap, fmt); + rc = _vsnprintf(str, sz, fmt, ap); + va_end (ap); + + return rc; +} + +#endif