1 /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.77 2007/10/26 21:50:10 mha Exp $ */
3 #if defined(_MSC_VER) || defined(__BORLANDC__)
4 #define WIN32_ONLY_COMPILER
7 #define _WIN32_WINNT 0x0500
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.
15 /* undefine and redefine after #include */
29 #include <sys/utime.h> /* for non-unicode version */
33 /* Must be here to avoid conflicting with prototype in windows.h */
34 #define mkdir(a,b) mkdir(a)
36 #define HAVE_FSYNC_WRITETHROUGH
37 #define HAVE_FSYNC_WRITETHROUGH_ONLY
38 #define ftruncate(a,b) chsize(a,b)
40 * Even though we don't support 'fsync' as a wal_sync_method,
41 * we do fsync() a few other places where _commit() is just fine.
43 #define fsync(fd) _commit(fd)
47 /* defines for dynamic linking on Win32 platform */
48 #if defined(WIN32) || defined(__CYGWIN__)
50 #if __GNUC__ && ! defined (__declspec)
51 #error You need egcs 1.1 or newer for compiling!
55 #define PGDLLIMPORT __declspec (dllexport)
56 #else /* not BUILDING_DLL */
57 #define PGDLLIMPORT __declspec (dllimport)
59 #else /* not CYGWIN, not MSVC, not MingW */
68 #undef HAVE_UNION_SEMUN
69 #define HAVE_UNION_SEMUN 1
74 #define IPC_PRIVATE 234564
75 #define IPC_NOWAIT 2048
91 * For WIN32, there is no wait() call so there are no wait() macros
92 * to interpret the return value of system(). Instead, system()
93 * return values < 0x100 are used for exit() termination, and higher
94 * values are used to indicated non-exit() termination, which is
95 * similar to a unix-style signal exit (think SIGSEGV ==
96 * STATUS_ACCESS_VIOLATION). Return values are broken up into groups:
98 * http://msdn2.microsoft.com/en-gb/library/aa489609.aspx
100 * NT_SUCCESS 0 - 0x3FFFFFFF
101 * NT_INFORMATION 0x40000000 - 0x7FFFFFFF
102 * NT_WARNING 0x80000000 - 0xBFFFFFFF
103 * NT_ERROR 0xC0000000 - 0xFFFFFFFF
105 * Effectively, we don't care on the severity of the return value from
106 * system(), we just need to know if it was because of exit() or generated
107 * by the system, and it seems values >= 0x100 are system-generated.
108 * See this URL for a list of WIN32 STATUS_* values:
110 * Wine (URL used in our error messages) -
111 * http://source.winehq.org/source/include/ntstatus.h
112 * Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt
113 * MS SDK - http://www.nologs.com/ntstatus.html
115 * It seems the exception lists are in both ntstatus.h and winnt.h, but
116 * ntstatus.h has a more comprehensive list, and it only contains
117 * exception values, rather than winnt, which contains lots of other
120 * http://www.microsoft.com/msj/0197/exception/exception.aspx
122 * The ExceptionCode parameter is the number that the operating system
123 * assigned to the exception. You can see a list of various exception codes
124 * in WINNT.H by searching for #defines that start with "STATUS_". For
125 * example, the code for the all-too-familiar STATUS_ACCESS_VIOLATION is
126 * 0xC0000005. A more complete set of exception codes can be found in
127 * NTSTATUS.H from the Windows NT DDK.
129 * Some day we might want to print descriptions for the most common
130 * exceptions, rather than printing an include file name. We could use
131 * RtlNtStatusToDosError() and pass to FormatMessage(), which can print
132 * the text of error values, but MinGW does not support
133 * RtlNtStatusToDosError().
135 #define WIFEXITED(w) (((w) & 0XFFFFFF00) == 0)
136 #define WIFSIGNALED(w) (!WIFEXITED(w))
137 #define WEXITSTATUS(w) (w)
138 #define WTERMSIG(w) (w)
140 #define sigmask(sig) ( 1 << ((sig)-1) )
142 /* Signal function return values */
146 #define SIG_DFL ((pqsigfunc)0)
147 #define SIG_ERR ((pqsigfunc)-1)
148 #define SIG_IGN ((pqsigfunc)1)
150 /* Some extra signals */
154 #define SIGABRT 22 /* Set to match W32 value -- not UNIX value */
163 #define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */
172 int tz_minuteswest; /* Minutes west of GMT. */
173 int tz_dsttime; /* Nonzero if DST is ever in effect. */
176 /* for setitimer in backend/port/win32/timer.c */
177 #define ITIMER_REAL 0
180 struct timeval it_interval;
181 struct timeval it_value;
183 int setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
187 * Supplement to <sys/types.h>.
189 * Perl already has typedefs for uid_t and gid_t.
191 #ifndef PLPERL_HAVE_UID_GID
197 #ifdef WIN32_ONLY_COMPILER
202 * Supplement to <sys/stat.h>.
204 #define lstat(path, sb) stat((path), (sb))
207 * Supplement to <fcntl.h>.
208 * This is the same value as _O_NOINHERIT in the MS header file. This is
209 * to ensure that we don't collide with a future definition. It means
210 * we cannot use _O_NOINHERIT ourselves.
212 #define O_DSYNC 0x0080
215 * Supplement to <errno.h>.
219 #define EINTR WSAEINTR
220 #define EAGAIN WSAEWOULDBLOCK
221 #define EMSGSIZE WSAEMSGSIZE
222 #define EAFNOSUPPORT WSAEAFNOSUPPORT
223 #define EWOULDBLOCK WSAEWOULDBLOCK
224 #define ECONNRESET WSAECONNRESET
225 #define EINPROGRESS WSAEINPROGRESS
226 #define ENOBUFS WSAENOBUFS
227 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
228 #define ECONNREFUSED WSAECONNREFUSED
229 #define EBADFD WSAENOTSOCK
230 #define EOPNOTSUPP WSAEOPNOTSUPP
233 /* In backend/port/win32/signal.c */
234 extern PGDLLIMPORT volatile int pg_signal_queue;
235 extern PGDLLIMPORT int pg_signal_mask;
236 extern HANDLE pgwin32_signal_event;
237 extern HANDLE pgwin32_initial_signal_pipe;
239 #define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask)
242 void pgwin32_signal_initialize(void);
243 HANDLE pgwin32_create_signal_listener(pid_t pid);
244 void pgwin32_dispatch_queued_signals(void);
245 void pg_queue_signal(int signum);
247 /* In backend/port/win32/socket.c */
249 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
250 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
251 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
252 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
253 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
254 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
256 SOCKET pgwin32_socket(int af, int type, int protocol);
257 SOCKET pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
258 int pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
259 int pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
260 int pgwin32_recv(SOCKET s, char *buf, int len, int flags);
261 int pgwin32_send(SOCKET s, char *buf, int len, int flags);
263 const char *pgwin32_socket_strerror(int err);
264 int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
266 /* in backend/port/win32/security.c */
267 extern int pgwin32_is_admin(void);
268 extern int pgwin32_is_service(void);
271 /* in port/win32error.c */
272 extern void _dosmaperr(unsigned long);
275 /* Things that exist in MingW headers, but need to be added to MSVC */
276 #ifdef WIN32_ONLY_COMPILER
278 typedef long ssize_t;
279 typedef unsigned short mode_t;
283 * Certain "standard edition" versions of MSVC throw a warning
284 * that later generates an error for "inline" statements, but
285 * __inline seems to work. e.g. Microsoft Visual C++ .NET
288 #define inline __inline
289 #define __inline__ __inline
292 #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
293 #define _S_IXUSR _S_IEXEC
294 #define _S_IWUSR _S_IWRITE
295 #define _S_IRUSR _S_IREAD
296 #define S_IRUSR _S_IRUSR
297 #define S_IWUSR _S_IWUSR
298 #define S_IXUSR _S_IXUSR
299 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
300 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
307 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
308 #define isnan(x) _isnan(x)
310 /* Pulled from Makefile.port in mingw */
311 #define DLSUFFIX ".dll"