test: add windows-only snprintf() function

Should fix the build after 96f32a2 inadvertently broke it.

There is no snprintf() on Windows because, hey, it's a C99 addition
and the people from Redmond, WA are still firmly stuck in 1989.
This commit is contained in:
Ben Noordhuis 2013-08-05 13:26:11 +02:00
parent 35ea88cf6b
commit fd082901f1

View File

@ -153,4 +153,32 @@ enum test_status {
return TEST_SKIP; \
} while (0)
#ifdef _WIN32
#include <stdarg.h>
/* Emulate snprintf() on Windows, _snprintf() doesn't zero-terminate the buffer
* on overflow...
*/
static int snprintf(char* buf, size_t len, const char* fmt, ...) {
va_list ap;
int n;
va_start(ap, fmt);
n = _vsprintf_p(buf, len, fmt, ap);
va_end(ap);
/* It's a sad fact of life that no one ever checks the return value of
* snprintf(). Zero-terminating the buffer hopefully reduces the risk
* of gaping security holes.
*/
if (n < 0)
if (len > 0)
buf[0] = '\0';
return n;
}
#endif
#endif /* TASK_H_ */