diff options
author | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2019-07-30 17:49:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-30 17:49:03 -0700 |
commit | 76d75aec66e1e6f173f3b6668601108ed453f3d3 (patch) | |
tree | b4bc5af6bb92804bae676dd32c3b21cdd78972aa /upb/port.c | |
parent | 423ea5ca9ce8da69611e6e95559efcb3a1ba8ad8 (diff) | |
parent | 7a1e6aa84ba857d2e3cdc6e5fd50e3bda210c164 (diff) |
Merge pull request #195 from veblush/vsnprintf
Fix compiler error on Windows
Diffstat (limited to 'upb/port.c')
-rw-r--r-- | upb/port.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/upb/port.c b/upb/port.c new file mode 100644 index 0000000..023f7dc --- /dev/null +++ b/upb/port.c @@ -0,0 +1,27 @@ + +#include "upb/upb.h" +#include "upb/port_def.inc" + +#ifdef UPB_MSVC_VSNPRINTF +/* Visual C++ earlier than 2015 doesn't have standard C99 snprintf and + * vsnprintf. To support them, missing functions are manually implemented + * using the existing secure functions. */ +int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg) { + if (!s) { + return _vscprintf(format, arg); + } + int ret = _vsnprintf_s(s, n, _TRUNCATE, format, arg); + if (ret < 0) { + ret = _vscprintf(format, arg); + } + return ret; +} + +int msvc_snprintf(char* s, size_t n, const char* format, ...) { + va_list arg; + va_start(arg, format); + int ret = msvc_vsnprintf(s, n, format, arg); + va_end(arg); + return ret; +} +#endif |