1 /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.96 2010/07/06 19:19:00 momjian Exp $ */
3 #if defined(_MSC_VER) || defined(__BORLANDC__)
4 #define WIN32_ONLY_COMPILER
7 #define _WIN32_WINNT 0x0501
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.
16 /* undefine and redefine after #include */
30 #include <sys/utime.h> /* for non-unicode version */
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)
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!
56 #define PGDLLIMPORT __declspec (dllexport)
57 #else /* not BUILDING_DLL */
58 #define PGDLLIMPORT __declspec (dllimport)
62 #define PGDLLEXPORT __declspec (dllexport)
64 #define PGDLLEXPORT __declspec (dllimport)
66 #else /* not CYGWIN, not MSVC, not MingW */
75 #undef HAVE_UNION_SEMUN
76 #define HAVE_UNION_SEMUN 1
81 #define IPC_PRIVATE 234564
82 #define IPC_NOWAIT 2048
98 * For WIN32, there is no wait() call so there are no wait() macros
99 * to interpret the return value of system(). Instead, system()
100 * return values < 0x100 are used for exit() termination, and higher
101 * values are used to indicated non-exit() termination, which is
102 * similar to a unix-style signal exit (think SIGSEGV ==
103 * STATUS_ACCESS_VIOLATION). Return values are broken up into groups:
105 * http://msdn2.microsoft.com/en-gb/library/aa489609.aspx
107 * NT_SUCCESS 0 - 0x3FFFFFFF
108 * NT_INFORMATION 0x40000000 - 0x7FFFFFFF
109 * NT_WARNING 0x80000000 - 0xBFFFFFFF
110 * NT_ERROR 0xC0000000 - 0xFFFFFFFF
112 * Effectively, we don't care on the severity of the return value from
113 * system(), we just need to know if it was because of exit() or generated
114 * by the system, and it seems values >= 0x100 are system-generated.
115 * See this URL for a list of WIN32 STATUS_* values:
117 * Wine (URL used in our error messages) -
118 * http://source.winehq.org/source/include/ntstatus.h
119 * Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt
120 * MS SDK - http://www.nologs.com/ntstatus.html
122 * It seems the exception lists are in both ntstatus.h and winnt.h, but
123 * ntstatus.h has a more comprehensive list, and it only contains
124 * exception values, rather than winnt, which contains lots of other
127 * http://www.microsoft.com/msj/0197/exception/exception.aspx
129 * The ExceptionCode parameter is the number that the operating system
130 * assigned to the exception. You can see a list of various exception codes
131 * in WINNT.H by searching for #defines that start with "STATUS_". For
132 * example, the code for the all-too-familiar STATUS_ACCESS_VIOLATION is
133 * 0xC0000005. A more complete set of exception codes can be found in
134 * NTSTATUS.H from the Windows NT DDK.
136 * Some day we might want to print descriptions for the most common
137 * exceptions, rather than printing an include file name. We could use
138 * RtlNtStatusToDosError() and pass to FormatMessage(), which can print
139 * the text of error values, but MinGW does not support
140 * RtlNtStatusToDosError().
142 #define WIFEXITED(w) (((w) & 0XFFFFFF00) == 0)
143 #define WIFSIGNALED(w) (!WIFEXITED(w))
144 #define WEXITSTATUS(w) (w)
145 #define WTERMSIG(w) (w)
147 #define sigmask(sig) ( 1 << ((sig)-1) )
149 /* Signal function return values */
153 #define SIG_DFL ((pqsigfunc)0)
154 #define SIG_ERR ((pqsigfunc)-1)
155 #define SIG_IGN ((pqsigfunc)1)
157 /* Some extra signals */
161 #define SIGABRT 22 /* Set to match W32 value -- not UNIX value */
170 #define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */
178 * New versions of mingw have gettimeofday() and also declare
179 * struct timezone to support it.
181 #ifndef HAVE_GETTIMEOFDAY
184 int tz_minuteswest; /* Minutes west of GMT. */
185 int tz_dsttime; /* Nonzero if DST is ever in effect. */
189 /* for setitimer in backend/port/win32/timer.c */
190 #define ITIMER_REAL 0
193 struct timeval it_interval;
194 struct timeval it_value;
197 int setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
200 * WIN32 does not provide 64-bit off_t, but does provide the functions operating
201 * with 64-bit offsets.
203 #define pgoff_t __int64
204 #ifdef WIN32_ONLY_COMPILER
205 #define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
206 #define ftello(stream) _ftelli64(stream)
208 #define fseeko(stream, offset, origin) fseeko64(stream, offset, origin)
209 #define ftello(stream) ftello64(stream)
213 * Supplement to <sys/types.h>.
215 * Perl already has typedefs for uid_t and gid_t.
217 #ifndef PLPERL_HAVE_UID_GID
223 #ifdef WIN32_ONLY_COMPILER
228 * Supplement to <sys/stat.h>.
230 #define lstat(path, sb) stat((path), (sb))
233 * Supplement to <fcntl.h>.
234 * This is the same value as _O_NOINHERIT in the MS header file. This is
235 * to ensure that we don't collide with a future definition. It means
236 * we cannot use _O_NOINHERIT ourselves.
238 #define O_DSYNC 0x0080
241 * Supplement to <errno.h>.
245 #define EINTR WSAEINTR
246 #define EAGAIN WSAEWOULDBLOCK
247 #define EMSGSIZE WSAEMSGSIZE
248 #define EAFNOSUPPORT WSAEAFNOSUPPORT
249 #define EWOULDBLOCK WSAEWOULDBLOCK
250 #define ECONNRESET WSAECONNRESET
251 #define EINPROGRESS WSAEINPROGRESS
252 #define ENOBUFS WSAENOBUFS
253 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
254 #define ECONNREFUSED WSAECONNREFUSED
255 #define EBADFD WSAENOTSOCK
256 #define EOPNOTSUPP WSAEOPNOTSUPP
259 /* In backend/port/win32/signal.c */
260 extern PGDLLIMPORT volatile int pg_signal_queue;
261 extern PGDLLIMPORT int pg_signal_mask;
262 extern HANDLE pgwin32_signal_event;
263 extern HANDLE pgwin32_initial_signal_pipe;
265 #define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask)
268 void pgwin32_signal_initialize(void);
269 HANDLE pgwin32_create_signal_listener(pid_t pid);
270 void pgwin32_dispatch_queued_signals(void);
271 void pg_queue_signal(int signum);
273 /* In backend/port/win32/socket.c */
275 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
276 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
277 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
278 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
279 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
280 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
282 SOCKET pgwin32_socket(int af, int type, int protocol);
283 SOCKET pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
284 int pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
285 int pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
286 int pgwin32_recv(SOCKET s, char *buf, int len, int flags);
287 int pgwin32_send(SOCKET s, char *buf, int len, int flags);
289 const char *pgwin32_socket_strerror(int err);
290 int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
292 extern int pgwin32_noblock;
294 /* in backend/port/win32/security.c */
295 extern int pgwin32_is_admin(void);
296 extern int pgwin32_is_service(void);
299 /* in backend/port/win32_shmem.c */
300 extern int pgwin32_ReserveSharedMemoryRegion(HANDLE);
302 /* in port/win32error.c */
303 extern void _dosmaperr(unsigned long);
305 /* in port/win32env.c */
306 extern int pgwin32_putenv(const char *);
307 extern void pgwin32_unsetenv(const char *);
309 #define putenv(x) pgwin32_putenv(x)
310 #define unsetenv(x) pgwin32_unsetenv(x)
312 /* Things that exist in MingW headers, but need to be added to MSVC & BCC */
313 #ifdef WIN32_ONLY_COMPILER
315 typedef long ssize_t;
317 typedef __int64 ssize_t;
321 typedef unsigned short mode_t;
325 #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
326 #define _S_IXUSR _S_IEXEC
327 #define _S_IWUSR _S_IWRITE
328 #define _S_IRUSR _S_IREAD
329 #define S_IRUSR _S_IRUSR
330 #define S_IWUSR _S_IWUSR
331 #define S_IXUSR _S_IXUSR
332 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
333 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
340 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
341 #define isnan(x) _isnan(x)
343 /* Pulled from Makefile.port in mingw */
344 #define DLSUFFIX ".dll"
348 /* for port/dirent.c */
349 #ifndef INVALID_FILE_ATTRIBUTES
350 #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
353 /* for port/open.c */
355 #define O_RANDOM 0x0010 /* File access is primarily random */
356 #define O_SEQUENTIAL 0x0020 /* File access is primarily sequential */
357 #define O_TEMPORARY 0x0040 /* Temporary file bit */
358 #define O_SHORT_LIVED 0x1000 /* Temporary storage file, try not to flush */
359 #define _O_SHORT_LIVED O_SHORT_LIVED
360 #endif /* ifndef O_RANDOM */
361 #endif /* __BORLANDC__ */