summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuhiro Fujii <y-fujii@mimosa-pudica.net>2017-06-24 14:30:19 +0900
committerYasuhiro Fujii <y-fujii@mimosa-pudica.net>2017-06-24 14:30:19 +0900
commitf76cd1b84083b449a853343775def314afdb3664 (patch)
treea1792397ed3c7fe318f99d9e089c5b1ae3461fe4
parente3bbd5cdbaee8a0a13fece93327662e344fb21bf (diff)
downloadjack2-f76cd1b84083b449a853343775def314afdb3664.tar.gz
add _snprintf() wrapper.
-rw-r--r--windows/JackCompilerDeps_os.h24
-rw-r--r--windows/JackSystemDeps_os.h5
2 files changed, 23 insertions, 6 deletions
diff --git a/windows/JackCompilerDeps_os.h b/windows/JackCompilerDeps_os.h
index 643856b2..09812d4f 100644
--- a/windows/JackCompilerDeps_os.h
+++ b/windows/JackCompilerDeps_os.h
@@ -40,9 +40,29 @@
#endif
#if defined(_MSC_VER) /* Added by JE - 31-01-2012 */
-#define vsnprintf _vsnprintf
-#define snprintf _snprintf
#define strdup _strdup
+#if _MSC_VER < 1900
+// This wrapper is not fully standard-compliant. _snprintf() does not
+// distinguish whether a result is truncated or a format error occurs.
+inline int vsnprintf(char* buf, size_t buf_len, const char* fmt, va_list args)
+{
+ int str_len = _vsnprintf(buf, buf_len - 1, fmt, args);
+ if (str_len == buf_len - 1 || str_len < 0) {
+ buf[buf_len - 1] = '\0';
+ return buf_len - 1;
+ }
+ return str_len;
+}
+
+inline int snprintf(char* buf, size_t buf_len, const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ int str_len = vsnprintf(buf, buf_len, fmt, args);
+ va_end(args);
+ return str_len;
+}
+#endif
#endif
#endif
diff --git a/windows/JackSystemDeps_os.h b/windows/JackSystemDeps_os.h
index 07f1bdfb..60718519 100644
--- a/windows/JackSystemDeps_os.h
+++ b/windows/JackSystemDeps_os.h
@@ -22,6 +22,7 @@
#define __JackSystemDeps_WIN32__
#include <windows.h>
+#include "JackCompilerDeps.h"
#ifndef PATH_MAX
#define PATH_MAX 512
@@ -49,10 +50,6 @@
#define JACK_DEBUG false
#endif
-#if defined(_MSC_VER)
-#define snprintf _snprintf
-#endif
-
inline int setenv(const char* name, const char* value, int overwrite)
{
if (overwrite == 0 && getenv(name) != NULL) {