1#ifndef __PLATFORM_H
2#define __PLATFORM_H
3
4#ifdef _WIN32
5#include <winsock2.h>
6#include <windows.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <io.h>
10#include <fcntl.h>
11#include <direct.h>
12#include <Ws2tcpip.h>
13#include <process.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#include "gettimeofday.h"
20#include "snprintf.h"
21#include "net.h"
22#include "w32_errno.h"
23#include "w32_stat.h"
24#include "random.h"
25#include "utf8_util.h"
26
27#ifdef __cplusplus
28}
29#else
30typedef unsigned short mode_t;
31#endif
32
33#define strcasecmp lstrcmpi
34#define strncasecmp strnicmp
35#define mkdir(path, mode) mkdir(path)
36#define sleep(sex) Sleep(1000 * (sex))
37#define getuid() 0
38#define getgid() 0
39
40char *strptime(const char *s, const char *format, struct tm *tm);
41
42#define srand w32_srand
43#define rand w32_rand
44#define socket w32_socket
45#define getsockopt w32_getsockopt
46#define setsockopt w32_setsockopt
47#define bind w32_bind
48#define listen w32_listen
49#define accept w32_accept
50#define connect w32_connect
51#define shutdown w32_shutdown
52#define send w32_send
53#define recv w32_recv
54#define closesocket w32_closesocket
55#define getservbyname w32_getservbyname
56#define getaddrinfo w32_getaddrinfo
57#ifdef gai_strerror
58#undef gai_strerror
59#endif
60#define gai_strerror w32_strerror
61#define freeaddrinfo w32_freeaddrinfo
62#define inet_ntop w32_inet_ntop
63#define inet_ntoa w32_inet_ntoa
64#define getpeername w32_getpeername
65#define select w32_select
66#define poll w32_poll
67#define strerror w32_strerror
68#define strerror_r w32_strerror_r
69#define ftruncate _chsize
70#define getpid GetCurrentProcessId
71
72#define PATH_MAX 32767
73#define WORDS_BIGENDIAN 0
74#define EAI_SYSTEM 0
75
76#else
77#define closesocket(s) close(s)
78#define cli_to_utf8_maybe_alloc(x) (x)
79#define cli_strdup_to_utf8(x) strdup(x)
80#endif
81
82#ifndef O_BINARY
83#define O_BINARY 0
84#endif
85
86#ifndef	FALSE
87#define FALSE (0)
88#endif
89#ifndef	TRUE
90#define TRUE (1)
91#endif
92
93#ifndef MIN
94#define MIN(a, b)	(((a) < (b)) ? (a) : (b))
95#endif
96#ifndef MAX
97#define MAX(a,b)	(((a) > (b)) ? (a) : (b))
98#endif
99
100#ifndef HAVE_IN_PORT_T
101typedef unsigned short in_port_t;
102#endif
103
104#ifndef HAVE_IN_ADDR_T
105typedef unsigned int in_addr_t;
106#endif
107
108#ifdef _WIN32
109#define PATHSEP "\\"
110#else
111#define PATHSEP "/"
112#endif
113
114#ifndef _WIN32
115#define CONFDIR_CLAMD CONFDIR PATHSEP "clamd.conf"
116#define CONFDIR_FRESHCLAM CONFDIR PATHSEP "freshclam.conf"
117#define CONFDIR_MILTER CONFDIR PATHSEP "clamav-milter.conf"
118#endif
119
120#ifndef WORDS_BIGENDIAN
121#define WORDS_BIGENDIAN 0
122#endif
123
124#ifdef _WIN32
125
126void w32_glob(int *argc_ptr, char ***argv_ptr);
127
128#if !defined(THIS_IS_LIBCLAMAV) && defined(_MSC_VER)
129#define LIBCLAMAV_EXPORT __declspec(dllimport)
130#else
131#define LIBCLAMAV_EXPORT
132#endif
133#undef HAVE_CONFIG_H
134
135#ifdef OUT
136#undef OUT
137#endif
138
139int real_main(int, char **);
140#define main                                 \
141    main(int argc, char **argv)              \
142    {                                        \
143        _setmode(_fileno(stdin), _O_BINARY); \
144        w32_glob(&argc, &argv);              \
145        return real_main(argc, argv);        \
146    };                                       \
147    int real_main
148
149#else
150#define LIBCLAMAV_EXPORT
151#endif
152
153#endif /* __PLATFORM_H */
154