• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2      This file is part of libmicrohttpd
3      Copyright (C) 2008 Christian Grothoff (and other contributing authors)
4 
5      This library is free software; you can redistribute it and/or
6      modify it under the terms of the GNU Lesser General Public
7      License as published by the Free Software Foundation; either
8      version 2.1 of the License, or (at your option) any later version.
9 
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Lesser General Public License for more details.
14 
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19 
20 /**
21  * @file platform.h
22  * @brief platform-specific includes for libmicrohttpd
23  * @author Christian Grothoff
24  *
25  * This file is included by the libmicrohttpd code
26  * before "microhttpd.h"; it provides the required
27  * standard headers (which are platform-specific).<p>
28  *
29  * Note that this file depends on our configure.ac
30  * build process and the generated config.h file.
31  * Hence you cannot include it directly in applications
32  * that use libmicrohttpd.
33  */
34 #ifndef MHD_PLATFORM_H
35 #define MHD_PLATFORM_H
36 
37 #include "MHD_config.h"
38 
39 #ifndef BUILDING_MHD_LIB
40 #ifdef _MHD_EXTERN
41 #undef _MHD_EXTERN
42 #endif /* _MHD_EXTERN */
43 #if defined(_WIN32) && defined(MHD_W32LIB)
44 #define _MHD_EXTERN extern
45 #elif defined (_WIN32) && defined(MHD_W32DLL)
46 #define _MHD_EXTERN __declspec(dllimport)
47 #else
48 #define _MHD_EXTERN extern
49 #endif
50 #elif !defined(_MHD_EXTERN) /* && BUILDING_MHD_LIB */
51 #if defined(_WIN32) && defined(MHD_W32LIB)
52 #define _MHD_EXTERN extern
53 #elif defined (_WIN32) && defined(MHD_W32DLL)
54 #define _MHD_EXTERN extern __declspec(dllexport)
55 #else
56 #define _MHD_EXTERN extern
57 #endif
58 #endif /* BUILDING_MHD_LIB */
59 
60 #define _XOPEN_SOURCE_EXTENDED  1
61 #if OS390
62 #define _OPEN_THREADS
63 #define _OPEN_SYS_SOCK_IPV6
64 #define _OPEN_MSGQ_EXT
65 #define _LP64
66 #endif
67 
68 #if defined(_WIN32)
69 #ifndef _WIN32_WINNT
70 #define _WIN32_WINNT 0x0501
71 #else // _WIN32_WINNT
72 #if _WIN32_WINNT < 0x0501
73 #error "Headers for Windows XP or later are required"
74 #endif // _WIN32_WINNT < 0x0501
75 #endif // _WIN32_WINNT
76 #ifndef WIN32_LEAN_AND_MEAN
77 #define WIN32_LEAN_AND_MEAN 1
78 #endif /* !WIN32_LEAN_AND_MEAN */
79 #endif // _WIN32
80 
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <stdint.h>
84 #include <string.h>
85 #ifdef HAVE_UNISTD_H
86 #include <unistd.h>
87 #endif
88 #include <stdarg.h>
89 #include <errno.h>
90 #include <fcntl.h>
91 #include <signal.h>
92 #include <stddef.h>
93 #ifdef MHD_USE_POSIX_THREADS
94 #undef HAVE_CONFIG_H
95 #include <pthread.h>
96 #define HAVE_CONFIG_H 1
97 #endif // MHD_USE_POSIX_THREADS
98 
99 /* different OSes have fd_set in
100    a broad range of header files;
101    we just include most of them (if they
102    are available) */
103 
104 
105 #ifdef OS_VXWORKS
106 #include <sockLib.h>
107 #include <netinet/in.h>
108 #include <stdarg.h>
109 #include <sys/mman.h>
110 #define RESTRICT __restrict__
111 #endif
112 #if HAVE_MEMORY_H
113 #include <memory.h>
114 #endif
115 
116 #if HAVE_SYS_SELECT_H
117 #include <sys/select.h>
118 #endif
119 #if HAVE_SYS_TYPES_H
120 #include <sys/types.h>
121 #endif
122 #if HAVE_SYS_TIME_H
123 #include <sys/time.h>
124 #endif
125 #if HAVE_SYS_STAT_H
126 #include <sys/stat.h>
127 #endif
128 #if HAVE_SYS_MSG_H
129 #include <sys/msg.h>
130 #endif
131 #if HAVE_SYS_MMAN_H
132 #include <sys/mman.h>
133 #endif
134 #if HAVE_NETDB_H
135 #include <netdb.h>
136 #endif
137 #if HAVE_NETINET_IN_H
138 #include <netinet/in.h>
139 #endif
140 #if HAVE_TIME_H
141 #include <time.h>
142 #endif
143 #if HAVE_SYS_SOCKET_H
144 #include <sys/socket.h>
145 #endif
146 #if HAVE_ARPA_INET_H
147 #include <arpa/inet.h>
148 #endif
149 
150 
151 #if defined(_WIN32) && !defined(__CYGWIN__)
152 #include <ws2tcpip.h>
153 #define sleep(seconds) (SleepEx((seconds)*1000, 1)/1000)
154 #define usleep(useconds) (void)SleepEx((useconds)/1000, 1)
155 #endif
156 
157 #if !defined(SHUT_WR) && defined(SD_SEND)
158 #define SHUT_WR SD_SEND
159 #endif
160 #if !defined(SHUT_RD) && defined(SD_RECEIVE)
161 #define SHUT_RD SD_RECEIVE
162 #endif
163 #if !defined(SHUT_RDWR) && defined(SD_BOTH)
164 #define SHUT_RDWR SD_BOTH
165 #endif
166 
167 #if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED)
168 #define _SSIZE_T_DEFINED
169 typedef intptr_t ssize_t;
170 #endif // !_SSIZE_T_DEFINED */
171 #ifndef MHD_SOCKET_DEFINED
172 /**
173  * MHD_socket is type for socket FDs
174  */
175 #if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
176 #define MHD_POSIX_SOCKETS 1
177 typedef int MHD_socket;
178 #define MHD_INVALID_SOCKET (-1)
179 #else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
180 #define MHD_WINSOCK_SOCKETS 1
181 #include <winsock2.h>
182 typedef SOCKET MHD_socket;
183 #define MHD_INVALID_SOCKET (INVALID_SOCKET)
184 #endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
185 #define MHD_SOCKET_DEFINED 1
186 #endif /* MHD_SOCKET_DEFINED */
187 
188 /* Force don't use pipes on W32 */
189 #if defined(_WIN32) && !defined(MHD_DONT_USE_PIPES)
190 #define MHD_DONT_USE_PIPES 1
191 #endif /* defined(_WIN32) && !defined(MHD_DONT_USE_PIPES) */
192 
193 /* MHD_pipe is type for pipe FDs*/
194 #ifndef MHD_DONT_USE_PIPES
195 typedef int MHD_pipe;
196 #else /* ! MHD_DONT_USE_PIPES */
197 typedef MHD_socket MHD_pipe;
198 #endif /* ! MHD_DONT_USE_PIPES */
199 
200 #if !defined(IPPROTO_IPV6) && defined(_MSC_FULL_VER) && _WIN32_WINNT >= 0x0501
201 /* VC use IPPROTO_IPV6 as part of enum */
202 #define IPPROTO_IPV6 IPPROTO_IPV6
203 #endif
204 
205 #endif
206