GNU libmicrohttpd  0.9.29
platform.h
Go to the documentation of this file.
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 
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 #if LINUX+0 && (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64)) && ! defined(_LARGEFILE64_SOURCE)
82 #define _LARGEFILE64_SOURCE 1
83 #endif
84 
85 #include <stdio.h>
86 #include <stdlib.h>
87 #include <stdint.h>
88 #include <string.h>
89 #ifdef HAVE_UNISTD_H
90 #include <unistd.h>
91 #endif
92 #include <stdarg.h>
93 #include <errno.h>
94 #include <fcntl.h>
95 #include <signal.h>
96 #include <stddef.h>
97 #ifdef MHD_USE_POSIX_THREADS
98 #undef HAVE_CONFIG_H
99 #include <pthread.h>
100 #define HAVE_CONFIG_H 1
101 #endif /* MHD_USE_POSIX_THREADS */
102 
103 /* different OSes have fd_set in
104  a broad range of header files;
105  we just include most of them (if they
106  are available) */
107 
108 
109 #ifdef OS_VXWORKS
110 #include <sockLib.h>
111 #include <netinet/in.h>
112 #include <stdarg.h>
113 #include <sys/mman.h>
114 #define RESTRICT __restrict__
115 #endif
116 #if HAVE_MEMORY_H
117 #include <memory.h>
118 #endif
119 
120 #if HAVE_SYS_SELECT_H
121 #include <sys/select.h>
122 #endif
123 #if HAVE_SYS_TYPES_H
124 #include <sys/types.h>
125 #endif
126 #if HAVE_SYS_TIME_H
127 #include <sys/time.h>
128 #endif
129 #if HAVE_SYS_STAT_H
130 #include <sys/stat.h>
131 #endif
132 #if HAVE_SYS_MSG_H
133 #include <sys/msg.h>
134 #endif
135 #if HAVE_SYS_MMAN_H
136 #include <sys/mman.h>
137 #endif
138 #if HAVE_NETDB_H
139 #include <netdb.h>
140 #endif
141 #if HAVE_NETINET_IN_H
142 #include <netinet/in.h>
143 #endif
144 #if HAVE_TIME_H
145 #include <time.h>
146 #endif
147 #if HAVE_SYS_SOCKET_H
148 #include <sys/socket.h>
149 #endif
150 #if HAVE_ARPA_INET_H
151 #include <arpa/inet.h>
152 #endif
153 
154 
155 #if defined(_WIN32) && !defined(__CYGWIN__)
156 #include <ws2tcpip.h>
157 #define sleep(seconds) ((SleepEx((seconds)*1000, 1)==0)?0:(seconds))
158 #define usleep(useconds) ((SleepEx((useconds)/1000, 1)==0)?0:-1)
159 #endif
160 
161 #if !defined(SHUT_WR) && defined(SD_SEND)
162 #define SHUT_WR SD_SEND
163 #endif
164 #if !defined(SHUT_RD) && defined(SD_RECEIVE)
165 #define SHUT_RD SD_RECEIVE
166 #endif
167 #if !defined(SHUT_RDWR) && defined(SD_BOTH)
168 #define SHUT_RDWR SD_BOTH
169 #endif
170 
171 #if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED)
172 #define _SSIZE_T_DEFINED
173 typedef intptr_t ssize_t;
174 #endif /* !_SSIZE_T_DEFINED */
175 #ifndef MHD_SOCKET_DEFINED
176 
179 #if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
180 #define MHD_POSIX_SOCKETS 1
181 typedef int MHD_socket;
182 #define MHD_INVALID_SOCKET (-1)
183 #else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
184 #define MHD_WINSOCK_SOCKETS 1
185 #include <winsock2.h>
186 typedef SOCKET MHD_socket;
187 #define MHD_INVALID_SOCKET (INVALID_SOCKET)
188 #endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
189 #define MHD_SOCKET_DEFINED 1
190 #endif /* MHD_SOCKET_DEFINED */
191 
192 #ifndef _WIN32
194 #else /* _WIN32 */
195 typedef long _MHD_TIMEVAL_TV_SEC_TYPE;
196 #endif /* _WIN32 */
197 
198 /* Force don't use pipes on W32 */
199 #if defined(_WIN32) && !defined(MHD_DONT_USE_PIPES)
200 #define MHD_DONT_USE_PIPES 1
201 #endif /* defined(_WIN32) && !defined(MHD_DONT_USE_PIPES) */
202 
203 /* MHD_pipe is type for pipe FDs*/
204 #ifndef MHD_DONT_USE_PIPES
205 typedef int MHD_pipe;
206 #else /* ! MHD_DONT_USE_PIPES */
207 typedef MHD_socket MHD_pipe;
208 #endif /* ! MHD_DONT_USE_PIPES */
209 
210 #if !defined(IPPROTO_IPV6) && defined(_MSC_FULL_VER) && _WIN32_WINNT >= 0x0501
211 /* VC use IPPROTO_IPV6 as part of enum */
212 #define IPPROTO_IPV6 IPPROTO_IPV6
213 #endif
214 
215 #endif
int MHD_socket
Definition: microhttpd.h:185
int MHD_pipe
Definition: platform.h:205
time_t _MHD_TIMEVAL_TV_SEC_TYPE
Definition: platform.h:193
int MHD_socket
Definition: platform.h:181