2020-12-05 11:26:32 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if MG_ARCH == MG_ARCH_WIN32
|
|
|
|
|
2021-07-13 07:13:06 +01:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _CRT_SECURE_NO_WARNINGS
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
|
|
|
|
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
|
|
|
#endif
|
|
|
|
|
2021-03-13 12:34:26 +00:00
|
|
|
#include <ctype.h>
|
2022-01-21 12:35:28 +00:00
|
|
|
#include <direct.h>
|
2021-03-13 12:34:26 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
2022-02-12 16:43:08 +00:00
|
|
|
#include <signal.h>
|
2021-03-13 12:34:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1700
|
|
|
|
#define __func__ ""
|
|
|
|
typedef __int64 int64_t;
|
|
|
|
typedef unsigned __int64 uint64_t;
|
|
|
|
typedef unsigned char uint8_t;
|
2021-01-25 10:08:15 +00:00
|
|
|
typedef char int8_t;
|
2020-12-05 11:26:32 +00:00
|
|
|
typedef unsigned short uint16_t;
|
2021-01-25 10:08:15 +00:00
|
|
|
typedef short int16_t;
|
2020-12-05 11:26:32 +00:00
|
|
|
typedef unsigned int uint32_t;
|
2021-01-25 10:08:15 +00:00
|
|
|
typedef int int32_t;
|
2021-01-26 12:16:58 +00:00
|
|
|
typedef enum { false = 0, true = 1 } bool;
|
2020-12-05 11:26:32 +00:00
|
|
|
#else
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2020-12-22 09:44:59 +00:00
|
|
|
#include <ws2tcpip.h>
|
2020-12-05 11:26:32 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-12 16:43:08 +00:00
|
|
|
#include <process.h>
|
2022-03-15 10:10:08 +00:00
|
|
|
#include <winerror.h>
|
2020-12-05 11:26:32 +00:00
|
|
|
#include <winsock2.h>
|
2020-12-23 21:05:46 +00:00
|
|
|
|
|
|
|
// Protect from calls like std::snprintf in app code
|
|
|
|
// See https://github.com/cesanta/mongoose/issues/1047
|
|
|
|
#ifndef __cplusplus
|
2020-12-05 11:26:32 +00:00
|
|
|
#define snprintf _snprintf
|
|
|
|
#define vsnprintf _vsnprintf
|
2021-09-27 13:52:39 +01:00
|
|
|
#ifndef strdup // For MSVC with _DEBUG, see #1359
|
2020-12-05 11:26:32 +00:00
|
|
|
#define strdup(x) _strdup(x)
|
2020-12-23 21:05:46 +00:00
|
|
|
#endif
|
2021-09-27 13:52:39 +01:00
|
|
|
#endif
|
2020-12-23 21:05:46 +00:00
|
|
|
|
2022-11-05 10:07:31 +00:00
|
|
|
#define MG_INVALID_SOCKET INVALID_SOCKET
|
|
|
|
#define MG_SOCKET_TYPE SOCKET
|
|
|
|
typedef unsigned long nfds_t;
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma comment(lib, "ws2_32.lib")
|
2022-10-31 10:40:34 +00:00
|
|
|
#ifndef alloca
|
2022-11-05 10:07:31 +00:00
|
|
|
#define alloca(a) _alloca(a)
|
|
|
|
#endif
|
2022-10-31 10:40:34 +00:00
|
|
|
#endif
|
2022-11-05 10:07:31 +00:00
|
|
|
#define poll(a, b, c) WSAPoll((a), (b), (c))
|
|
|
|
#define closesocket(x) closesocket(x)
|
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
typedef int socklen_t;
|
|
|
|
#define MG_DIRSEP '\\'
|
2022-08-06 22:19:55 +01:00
|
|
|
|
|
|
|
#ifndef MG_PATH_MAX
|
|
|
|
#define MG_PATH_MAX FILENAME_MAX
|
2020-12-24 07:26:50 +00:00
|
|
|
#endif
|
2022-08-06 22:19:55 +01:00
|
|
|
|
2023-02-01 12:25:30 +00:00
|
|
|
#ifndef SO_EXCLUSIVEADDRUSE
|
|
|
|
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
2020-12-05 11:26:32 +00:00
|
|
|
#endif
|
2021-07-24 10:35:48 +01:00
|
|
|
|
2023-02-01 12:25:30 +00:00
|
|
|
#define MG_SOCK_ERR(errcode) ((errcode) < 0 ? WSAGetLastError() : 0)
|
|
|
|
|
|
|
|
#define MG_SOCK_PENDING(errcode) \
|
|
|
|
(((errcode) < 0) && \
|
|
|
|
(WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS || \
|
|
|
|
WSAGetLastError() == WSAEWOULDBLOCK))
|
|
|
|
|
|
|
|
#define MG_SOCK_RESET(errcode) \
|
|
|
|
(((errcode) < 0) && (WSAGetLastError() == WSAECONNRESET))
|
|
|
|
|
2021-12-22 18:04:27 +00:00
|
|
|
#define realpath(a, b) _fullpath((b), (a), MG_PATH_MAX)
|
|
|
|
#define sleep(x) Sleep(x)
|
2022-01-21 12:35:28 +00:00
|
|
|
#define mkdir(a, b) _mkdir(a)
|
2021-12-22 18:04:27 +00:00
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(x) (((x) &_S_IFMT) == _S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
2022-02-14 11:32:01 +00:00
|
|
|
#ifndef MG_ENABLE_DIRLIST
|
|
|
|
#define MG_ENABLE_DIRLIST 1
|
|
|
|
#endif
|
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
#endif
|