Make mjs & frozen vc98 & vc2017 friendly

PUBLISHED_FROM=7cde8b374d5e318b5cdd69fc5b4de86b2a9552f5
This commit is contained in:
Бобби 2017-10-27 11:24:27 +01:00 committed by Cesanta Bot
parent 6e50fe4475
commit 00d1d2c0e7
2 changed files with 32 additions and 3 deletions

View File

@ -1936,12 +1936,24 @@ int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
*buf = NULL; /* LCOV_EXCL_START */
while (len < 0) {
MG_FREE(*buf);
if (size == 0) {
size = 5;
}
size *= 2;
if ((*buf = (char *) MG_MALLOC(size)) == NULL) break;
if ((*buf = (char *) MG_MALLOC(size)) == NULL) {
len = -1;
break;
}
va_copy(ap_copy, ap);
len = vsnprintf(*buf, size, fmt, ap_copy);
len = vsnprintf(*buf, size - 1, fmt, ap_copy);
va_end(ap_copy);
}
/*
* Microsoft version of vsnprintf() is not always null-terminated, so put
* the terminator manually
*/
(*buf)[len] = 0;
/* LCOV_EXCL_STOP */
} else if (len >= (int) size) {
/* Standard-compliant code path. Allocate a buffer that is large enough. */

View File

@ -210,6 +210,12 @@
#include <windows.h>
#include <process.h>
#if _MSC_VER < 1700
typedef int bool;
#else
#include <stdbool.h>
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1800
#define strdup _strdup
#endif
@ -323,9 +329,16 @@ typedef struct _stati64 cs_stat_t;
#define MG_NET_IF MG_NET_IF_SOCKET
#endif
int rmdir(const char *dirname);
unsigned int sleep(unsigned int seconds);
/* https://stackoverflow.com/questions/16647819/timegm-cross-platform */
#define timegm _mkgmtime
#define gmtime_r(a, b) \
do { \
*(b) = *gmtime(a); \
} while (0)
#endif /* CS_PLATFORM == CS_P_WINDOWS */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */
#ifdef MG_MODULE_LINES
@ -374,6 +387,7 @@ unsigned int sleep(unsigned int seconds);
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -493,6 +507,7 @@ typedef struct stat cs_stat_t;
#include <fcntl.h>
#include <inttypes.h>
#include <machine/endian.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
@ -536,6 +551,7 @@ typedef struct stat cs_stat_t;
#include <fcntl.h>
#include <inttypes.h>
#include <machine/endian.h>
#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
@ -642,6 +658,7 @@ int inet_pton(int af, const char *src, void *dst);
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <time.h>