diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-04-01 01:15:17 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-04-01 01:17:25 +0200 |
commit | a4a04f932ed99a8195f6d44227b1e89f5b9ea381 (patch) | |
tree | 40211ed34e8104d3a6371e240f18e6ea6b423d6b /src/node_internals.h | |
parent | dee8c51547860c05d33b695b37daa06633a022b8 (diff) | |
download | android-node-v8-a4a04f932ed99a8195f6d44227b1e89f5b9ea381.tar.gz android-node-v8-a4a04f932ed99a8195f6d44227b1e89f5b9ea381.tar.bz2 android-node-v8-a4a04f932ed99a8195f6d44227b1e89f5b9ea381.zip |
node: provide snprintf implementation on windows
_snprintf() doesn't zero-terminate the buffer on overflow.
Diffstat (limited to 'src/node_internals.h')
-rw-r--r-- | src/node_internals.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/node_internals.h b/src/node_internals.h index 0646727e1b..8d073927b8 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -27,7 +27,17 @@ namespace node { #ifdef _WIN32 -# define snprintf _snprintf +// emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer +// on overflow... +#include <stdarg.h> +inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + int n = _vsprintf_p(buf, len, fmt, ap); + if (len) buf[len - 1] = '\0'; + va_end(ap); + return n; +} #endif #ifndef offset_of |