1 /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.69 2007/01/23 03:28:49 momjian Exp $ */
3 #if defined(_MSC_VER) || defined(__BORLANDC__)
4 #define WIN32_ONLY_COMPILER
7 /* undefine and redefine after #include */
21 #include <sys/utime.h> /* for non-unicode version */
25 /* Must be here to avoid conflicting with prototype in windows.h */
26 #define mkdir(a,b) mkdir(a)
28 #define HAVE_FSYNC_WRITETHROUGH
29 #define HAVE_FSYNC_WRITETHROUGH_ONLY
30 #define ftruncate(a,b) chsize(a,b)
32 * Even though we don't support 'fsync' as a wal_sync_method,
33 * we do fsync() a few other places where _commit() is just fine.
35 #define fsync(fd) _commit(fd)
39 /* defines for dynamic linking on Win32 platform */
40 #if defined(WIN32) || defined(__CYGWIN__)
42 #if __GNUC__ && ! defined (__declspec)
43 #error You need egcs 1.1 or newer for compiling!
47 #define DLLIMPORT __declspec (dllexport)
48 #else /* not BUILDING_DLL */
49 #define DLLIMPORT __declspec (dllimport)
51 #else /* not CYGWIN, not MSVC, not MingW */
60 #undef HAVE_UNION_SEMUN
61 #define HAVE_UNION_SEMUN 1
66 #define IPC_PRIVATE 234564
67 #define IPC_NOWAIT 2048
88 int shmdt(const void *shmaddr);
89 void *shmat(int memId, void *shmaddr, int flag);
90 int shmctl(int shmid, int flag, struct shmid_ds * dummy);
91 int shmget(int memKey, int size, int flag);
100 struct semid_ds *buf;
101 unsigned short *array;
111 int semctl(int semId, int semNum, int flag, union semun);
112 int semget(int semKey, int semNum, int flags);
113 int semop(int semId, struct sembuf * sops, int flag);
119 * For WIN32, there is no wait() call so there are no wait() macros
120 * to interpret the return value of system(). Instead, system()
121 * return values < 0x100 are used for exit() termination, and higher
122 * values are used to indicated non-exit() termination, which is
123 * similar to a unix-style signal exit (think SIGSEGV ==
124 * STATUS_ACCESS_VIOLATION). Return values are broken up into groups:
126 * http://msdn2.microsoft.com/en-gb/library/aa489609.aspx
128 * NT_SUCCESS 0 - 0x3FFFFFFF
129 * NT_INFORMATION 0x40000000 - 0x7FFFFFFF
130 * NT_WARNING 0x80000000 - 0xBFFFFFFF
131 * NT_ERROR 0xC0000000 - 0xFFFFFFFF
133 * Effectively, we don't care on the severity of the return value from
134 * system(), we just need to know if it was because of exit() or generated
135 * by the system, and it seems values >= 0x100 are system-generated.
136 * See this URL for a list of WIN32 STATUS_* values:
138 * Wine (URL used in our error messages) -
139 * http://source.winehq.org/source/include/ntstatus.h
140 * Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt
141 * MS SDK - http://www.nologs.com/ntstatus.html
143 * Some day we might want to print descriptions for the most common
144 * exceptions, rather than printing a URL. FormatMessage() can print
145 * the text of error values, but not exception values.
147 #define WIFEXITED(w) (((w) & 0XFFFFFF00) == 0)
148 #define WIFSIGNALED(w) (!WIFEXITED(w))
149 #define WEXITSTATUS(w) (w)
150 #define WTERMSIG(w) (w)
152 #define sigmask(sig) ( 1 << ((sig)-1) )
154 /* Signal function return values */
158 #define SIG_DFL ((pqsigfunc)0)
159 #define SIG_ERR ((pqsigfunc)-1)
160 #define SIG_IGN ((pqsigfunc)1)
162 /* Some extra signals */
166 #define SIGABRT 22 /* Set to match W32 value -- not UNIX value */
175 #define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */
184 int tz_minuteswest; /* Minutes west of GMT. */
185 int tz_dsttime; /* Nonzero if DST is ever in effect. */
188 /* for setitimer in backend/port/win32/timer.c */
189 #define ITIMER_REAL 0
192 struct timeval it_interval;
193 struct timeval it_value;
195 int setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
199 * Supplement to <sys/types.h>.
201 * Perl already has typedefs for uid_t and gid_t.
203 #ifndef PLPERL_HAVE_UID_GID
209 #ifdef WIN32_ONLY_COMPILER
214 * Supplement to <sys/stat.h>.
216 #define lstat(path, sb) stat((path), (sb))
219 * Supplement to <fcntl.h>.
220 * This is the same value as _O_NOINHERIT in the MS header file. This is
221 * to ensure that we don't collide with a future definition. It means
222 * we cannot use _O_NOINHERIT ourselves.
224 #define O_DSYNC 0x0080
227 * Supplement to <errno.h>.
231 #define EINTR WSAEINTR
232 #define EAGAIN WSAEWOULDBLOCK
233 #define EMSGSIZE WSAEMSGSIZE
234 #define EAFNOSUPPORT WSAEAFNOSUPPORT
235 #define EWOULDBLOCK WSAEWOULDBLOCK
236 #define ECONNRESET WSAECONNRESET
237 #define EINPROGRESS WSAEINPROGRESS
238 #define ENOBUFS WSAENOBUFS
239 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
240 #define ECONNREFUSED WSAECONNREFUSED
241 #define EBADFD WSAENOTSOCK
242 #define EOPNOTSUPP WSAEOPNOTSUPP
245 /* In backend/port/win32/signal.c */
246 extern DLLIMPORT volatile int pg_signal_queue;
247 extern DLLIMPORT int pg_signal_mask;
248 extern HANDLE pgwin32_signal_event;
249 extern HANDLE pgwin32_initial_signal_pipe;
251 #define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask)
254 void pgwin32_signal_initialize(void);
255 HANDLE pgwin32_create_signal_listener(pid_t pid);
256 void pgwin32_dispatch_queued_signals(void);
257 void pg_queue_signal(int signum);
259 /* In backend/port/win32/socket.c */
261 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
262 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
263 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
264 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
265 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
266 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
268 SOCKET pgwin32_socket(int af, int type, int protocol);
269 SOCKET pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
270 int pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
271 int pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
272 int pgwin32_recv(SOCKET s, char *buf, int len, int flags);
273 int pgwin32_send(SOCKET s, char *buf, int len, int flags);
275 const char *pgwin32_socket_strerror(int err);
276 int pgwin32_waitforsinglesocket(SOCKET s, int what);
278 /* in backend/port/win32/security.c */
279 extern int pgwin32_is_admin(void);
280 extern int pgwin32_is_service(void);
283 /* in port/win32error.c */
284 extern void _dosmaperr(unsigned long);
287 /* Things that exist in MingW headers, but need to be added to MSVC */
288 #ifdef WIN32_ONLY_COMPILER
290 typedef long ssize_t;
291 typedef unsigned short mode_t;
295 * Certain "standard edition" versions of MSVC throw a warning
296 * that later generates an error for "inline" statements, but
297 * __inline seems to work. e.g. Microsoft Visual C++ .NET
300 #define inline __inline
301 #define __inline__ __inline
304 #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
305 #define _S_IXUSR _S_IEXEC
306 #define _S_IWUSR _S_IWRITE
307 #define _S_IRUSR _S_IREAD
308 #define S_IRUSR _S_IRUSR
309 #define S_IWUSR _S_IWUSR
310 #define S_IXUSR _S_IXUSR
311 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
312 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
319 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
320 #define isnan(x) _isnan(x)
323 #define BIG_ENDIAN 4321
325 #ifndef LITTLE_ENDIAN
326 #define LITTLE_ENDIAN 1234
329 #define PDP_ENDIAN 3412
333 #define BYTE_ORDER LITTLE_ENDIAN
336 /* Pulled from Makefile.port in mingw */
337 #define DLSUFFIX ".dll"