Fix obsolete comment regarding FSM truncation.
[PostgreSQL.git] / src / include / port / win32.h
blobfc65515fb51f690a7d3e1c724cfab072a62b86ef
1 /* $PostgreSQL$ */
3 #if defined(_MSC_VER) || defined(__BORLANDC__)
4 #define WIN32_ONLY_COMPILER
5 #endif
7 #define _WIN32_WINNT 0x0500
8 /*
9 * Always build with SSPI support. Keep it as a #define in case
10 * we want a switch to disable it sometime in the future.
12 #ifndef __BORLANDC__
13 #define ENABLE_SSPI 1
14 #endif
16 /* undefine and redefine after #include */
17 #undef mkdir
19 #undef ERROR
20 #define _WINSOCKAPI_
21 #include <windows.h>
22 #include <winsock2.h>
23 #include <ws2tcpip.h>
24 #undef small
25 #include <process.h>
26 #include <signal.h>
27 #include <errno.h>
28 #include <direct.h>
29 #ifndef __BORLANDC__
30 #include <sys/utime.h> /* for non-unicode version */
31 #endif
32 #undef near
34 /* Must be here to avoid conflicting with prototype in windows.h */
35 #define mkdir(a,b) mkdir(a)
37 #define HAVE_FSYNC_WRITETHROUGH
38 #define HAVE_FSYNC_WRITETHROUGH_ONLY
39 #define ftruncate(a,b) chsize(a,b)
41 * Even though we don't support 'fsync' as a wal_sync_method,
42 * we do fsync() a few other places where _commit() is just fine.
44 #define fsync(fd) _commit(fd)
46 #define USES_WINSOCK
48 /* defines for dynamic linking on Win32 platform */
49 #if defined(WIN32) || defined(__CYGWIN__)
51 #if __GNUC__ && ! defined (__declspec)
52 #error You need egcs 1.1 or newer for compiling!
53 #endif
55 #ifdef BUILDING_DLL
56 #define PGDLLIMPORT __declspec (dllexport)
57 #else /* not BUILDING_DLL */
58 #define PGDLLIMPORT __declspec (dllimport)
59 #endif
60 #else /* not CYGWIN, not MSVC, not MingW */
62 #define PGDLLIMPORT
63 #endif
67 * IPC defines
69 #undef HAVE_UNION_SEMUN
70 #define HAVE_UNION_SEMUN 1
72 #define IPC_RMID 256
73 #define IPC_CREAT 512
74 #define IPC_EXCL 1024
75 #define IPC_PRIVATE 234564
76 #define IPC_NOWAIT 2048
77 #define IPC_STAT 4096
79 #define EACCESS 2048
80 #define EIDRM 4096
82 #define SETALL 8192
83 #define GETNCNT 16384
84 #define GETVAL 65536
85 #define SETVAL 131072
86 #define GETPID 262144
90 * Signal stuff
92 * For WIN32, there is no wait() call so there are no wait() macros
93 * to interpret the return value of system(). Instead, system()
94 * return values < 0x100 are used for exit() termination, and higher
95 * values are used to indicated non-exit() termination, which is
96 * similar to a unix-style signal exit (think SIGSEGV ==
97 * STATUS_ACCESS_VIOLATION). Return values are broken up into groups:
99 * http://msdn2.microsoft.com/en-gb/library/aa489609.aspx
101 * NT_SUCCESS 0 - 0x3FFFFFFF
102 * NT_INFORMATION 0x40000000 - 0x7FFFFFFF
103 * NT_WARNING 0x80000000 - 0xBFFFFFFF
104 * NT_ERROR 0xC0000000 - 0xFFFFFFFF
106 * Effectively, we don't care on the severity of the return value from
107 * system(), we just need to know if it was because of exit() or generated
108 * by the system, and it seems values >= 0x100 are system-generated.
109 * See this URL for a list of WIN32 STATUS_* values:
111 * Wine (URL used in our error messages) -
112 * http://source.winehq.org/source/include/ntstatus.h
113 * Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt
114 * MS SDK - http://www.nologs.com/ntstatus.html
116 * It seems the exception lists are in both ntstatus.h and winnt.h, but
117 * ntstatus.h has a more comprehensive list, and it only contains
118 * exception values, rather than winnt, which contains lots of other
119 * things:
121 * http://www.microsoft.com/msj/0197/exception/exception.aspx
123 * The ExceptionCode parameter is the number that the operating system
124 * assigned to the exception. You can see a list of various exception codes
125 * in WINNT.H by searching for #defines that start with "STATUS_". For
126 * example, the code for the all-too-familiar STATUS_ACCESS_VIOLATION is
127 * 0xC0000005. A more complete set of exception codes can be found in
128 * NTSTATUS.H from the Windows NT DDK.
130 * Some day we might want to print descriptions for the most common
131 * exceptions, rather than printing an include file name. We could use
132 * RtlNtStatusToDosError() and pass to FormatMessage(), which can print
133 * the text of error values, but MinGW does not support
134 * RtlNtStatusToDosError().
136 #define WIFEXITED(w) (((w) & 0XFFFFFF00) == 0)
137 #define WIFSIGNALED(w) (!WIFEXITED(w))
138 #define WEXITSTATUS(w) (w)
139 #define WTERMSIG(w) (w)
141 #define sigmask(sig) ( 1 << ((sig)-1) )
143 /* Signal function return values */
144 #undef SIG_DFL
145 #undef SIG_ERR
146 #undef SIG_IGN
147 #define SIG_DFL ((pqsigfunc)0)
148 #define SIG_ERR ((pqsigfunc)-1)
149 #define SIG_IGN ((pqsigfunc)1)
151 /* Some extra signals */
152 #define SIGHUP 1
153 #define SIGQUIT 3
154 #define SIGTRAP 5
155 #define SIGABRT 22 /* Set to match W32 value -- not UNIX value */
156 #define SIGKILL 9
157 #define SIGPIPE 13
158 #define SIGALRM 14
159 #define SIGSTOP 17
160 #define SIGTSTP 18
161 #define SIGCONT 19
162 #define SIGCHLD 20
163 #define SIGTTIN 21
164 #define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */
165 #define SIGWINCH 28
166 #ifndef __BORLANDC__
167 #define SIGUSR1 30
168 #define SIGUSR2 31
169 #endif
172 * New versions of mingw have gettimeofday() and also declare
173 * struct timezone to support it.
175 #ifndef HAVE_GETTIMEOFDAY
176 struct timezone
178 int tz_minuteswest; /* Minutes west of GMT. */
179 int tz_dsttime; /* Nonzero if DST is ever in effect. */
181 #endif
183 /* for setitimer in backend/port/win32/timer.c */
184 #define ITIMER_REAL 0
185 struct itimerval
187 struct timeval it_interval;
188 struct timeval it_value;
191 int setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
195 * Supplement to <sys/types.h>.
197 * Perl already has typedefs for uid_t and gid_t.
199 #ifndef PLPERL_HAVE_UID_GID
200 typedef int uid_t;
201 typedef int gid_t;
202 #endif
203 typedef long key_t;
205 #ifdef WIN32_ONLY_COMPILER
206 typedef int pid_t;
207 #endif
210 * Supplement to <sys/stat.h>.
212 #define lstat(path, sb) stat((path), (sb))
215 * Supplement to <fcntl.h>.
216 * This is the same value as _O_NOINHERIT in the MS header file. This is
217 * to ensure that we don't collide with a future definition. It means
218 * we cannot use _O_NOINHERIT ourselves.
220 #define O_DSYNC 0x0080
223 * Supplement to <errno.h>.
225 #undef EAGAIN
226 #undef EINTR
227 #define EINTR WSAEINTR
228 #define EAGAIN WSAEWOULDBLOCK
229 #define EMSGSIZE WSAEMSGSIZE
230 #define EAFNOSUPPORT WSAEAFNOSUPPORT
231 #define EWOULDBLOCK WSAEWOULDBLOCK
232 #define ECONNRESET WSAECONNRESET
233 #define EINPROGRESS WSAEINPROGRESS
234 #define ENOBUFS WSAENOBUFS
235 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
236 #define ECONNREFUSED WSAECONNREFUSED
237 #define EBADFD WSAENOTSOCK
238 #define EOPNOTSUPP WSAEOPNOTSUPP
241 /* In backend/port/win32/signal.c */
242 extern PGDLLIMPORT volatile int pg_signal_queue;
243 extern PGDLLIMPORT int pg_signal_mask;
244 extern HANDLE pgwin32_signal_event;
245 extern HANDLE pgwin32_initial_signal_pipe;
247 #define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask)
250 void pgwin32_signal_initialize(void);
251 HANDLE pgwin32_create_signal_listener(pid_t pid);
252 void pgwin32_dispatch_queued_signals(void);
253 void pg_queue_signal(int signum);
255 /* In backend/port/win32/socket.c */
256 #ifndef FRONTEND
257 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
258 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
259 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
260 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
261 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
262 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
264 SOCKET pgwin32_socket(int af, int type, int protocol);
265 SOCKET pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
266 int pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
267 int pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
268 int pgwin32_recv(SOCKET s, char *buf, int len, int flags);
269 int pgwin32_send(SOCKET s, char *buf, int len, int flags);
271 const char *pgwin32_socket_strerror(int err);
272 int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
274 /* in backend/port/win32/security.c */
275 extern int pgwin32_is_admin(void);
276 extern int pgwin32_is_service(void);
277 #endif
279 /* in port/win32error.c */
280 extern void _dosmaperr(unsigned long);
283 /* Things that exist in MingW headers, but need to be added to MSVC */
284 #ifdef WIN32_ONLY_COMPILER
285 typedef long ssize_t;
286 #ifndef __BORLANDC__
287 typedef unsigned short mode_t;
288 #endif
291 * Certain "standard edition" versions of MSVC throw a warning
292 * that later generates an error for "inline" statements, but
293 * __inline seems to work. e.g. Microsoft Visual C++ .NET
294 * Version 7.1.3088
296 #define inline __inline
297 #define __inline__ __inline
299 #ifndef __BORLANDC__
300 #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
301 #define _S_IXUSR _S_IEXEC
302 #define _S_IWUSR _S_IWRITE
303 #define _S_IRUSR _S_IREAD
304 #define S_IRUSR _S_IRUSR
305 #define S_IWUSR _S_IWUSR
306 #define S_IXUSR _S_IXUSR
307 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
308 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
309 #endif
311 #define F_OK 0
312 #define W_OK 2
313 #define R_OK 4
315 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
316 #define isnan(x) _isnan(x)
318 /* Pulled from Makefile.port in mingw */
319 #define DLSUFFIX ".dll"
321 #endif