Skip to content

Commit 094c28c

Browse files
committed
[c89stringutils/c89stringutils_string_extras.h] Fix CRT for MSVC within jasprintf
1 parent efa52aa commit 094c28c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

c89stringutils/c89stringutils_string_extras.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ char *jasprintf(char **unto, const char *fmt, ...) {
368368
size_t base_length = unto && *unto ? strlen(*unto) : 0;
369369
int length;
370370
char *result;
371-
371+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
372+
int len;
373+
char *res_buf;
374+
#endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
375+
defined(__NT__) */
372376
va_start(args, fmt);
373377
/* check length for failure */
374378
length = vsnprintf(NULL, 0, fmt, args);
@@ -379,7 +383,15 @@ char *jasprintf(char **unto, const char *fmt, ...) {
379383

380384
va_start(args, fmt);
381385
/* check for failure*/
386+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
387+
len = _vscprintf(fmt, args) + 1;
388+
res_buf = (char *)malloc(len * sizeof(char));
389+
if (res_buf != NULL)
390+
vsprintf_s(res_buf, len, fmt, args);
391+
#else
382392
vsprintf(result + base_length, fmt, args);
393+
#endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
394+
defined(__NT__) */
383395
va_end(args);
384396

385397
if (unto)

0 commit comments

Comments
 (0)