]> granicus.if.org Git - postgresql/blobdiff - src/include/port/win32.h
Rearrange MSVC errcode hack, fix incorrect _MSC_VER test. Magnus
[postgresql] / src / include / port / win32.h
index 6a70bcc095dcbbf1853ca1332e05da934d2fcd03..f5e17aae3ecb285aec816e949b1acd78e980eb15 100644 (file)
@@ -1,25 +1,41 @@
-/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.27 2004/07/23 01:58:36 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.61 2006/10/03 20:33:20 tgl Exp $ */
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+#define        WIN32_ONLY_COMPILER
+#endif
 
 /* undefine and redefine after #include */
 #undef mkdir
 
 #undef ERROR
+#define _WINSOCKAPI_
 #include <windows.h>
-#include <winsock.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#undef small
 #include <process.h>
+#include <signal.h>
+#include <errno.h>
+#include <direct.h>
+#include <sys/utime.h> /* for non-unicode version */
 #undef near
 
 /* Must be here to avoid conflicting with prototype in windows.h */
 #define mkdir(a,b)     mkdir(a)
 
-
-#define fsync(a)       _commit(a)
+#define HAVE_FSYNC_WRITETHROUGH
+#define HAVE_FSYNC_WRITETHROUGH_ONLY
 #define ftruncate(a,b) chsize(a,b)
+/*
+ *     Even though we don't support 'fsync' as a wal_sync_method,
+ *     we do fsync() a few other places where _commit() is just fine.
+ */
+#define fsync(fd) _commit(fd)
 
 #define USES_WINSOCK
 
 /* defines for dynamic linking on Win32 platform */
-#if defined(__CYGWIN__) || defined(__MINGW32__)
+#if defined(WIN32) || defined(__CYGWIN__)
 
 #if __GNUC__ && ! defined (__declspec)
 #error You need egcs 1.1 or newer for compiling!
 #define DLLIMPORT __declspec (dllimport)
 #endif
 
-#elif defined(WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__))           /* not CYGWIN or MingW */
-
-#if defined(_DLL)
-#define DLLIMPORT __declspec (dllexport)
-#else                                                  /* not _DLL */
-#define DLLIMPORT __declspec (dllimport)
-#endif
-
 #else                                                  /* not CYGWIN, not MSVC, not MingW */
 
 #define DLLIMPORT
 #endif
 
+
 /*
  *     IPC defines
  */
@@ -103,13 +112,20 @@ int                       semget(int semKey, int semNum, int flags);
 int                    semop(int semId, struct sembuf * sops, int flag);
 
 
-/* In backend/port/win32/signal.c */
-void pgwin32_signal_initialize(void);
-extern DLLIMPORT HANDLE pgwin32_signal_event;
-void pgwin32_dispatch_queued_signals(void);
-void pg_queue_signal(int signum);
+/*
+ *     Signal stuff
+ *     WIN32 doesn't have wait(), so the return value for children
+ *     is simply the return value specified by the child, without
+ *     any additional information on whether the child terminated
+ *     on its own or via a signal.  These macros are also used
+ *     to interpret the return value of system().
+ */
+#define WEXITSTATUS(w) (w)
+#define WIFEXITED(w)   (true)
+#define WIFSIGNALED(w) (false)
+#define WTERMSIG(w)            (0)
 
-#define sigmask(sig) ( 1 << (sig-1) )
+#define sigmask(sig) ( 1 << ((sig)-1) )
 
 /* Signal function return values */
 #undef SIG_DFL
@@ -119,50 +135,16 @@ void pg_queue_signal(int signum);
 #define SIG_ERR ((pqsigfunc)-1)
 #define SIG_IGN ((pqsigfunc)1)
 
-#ifndef FRONTEND
-#define pg_usleep(t) pgwin32_backend_usleep(t)
-void pgwin32_backend_usleep(long microsec);
-#endif
-
-/* In backend/port/win32/socket.c */
-#ifndef FRONTEND
-#define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
-#define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
-#define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
-#define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
-#define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
-#define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
-
-SOCKET pgwin32_socket(int af, int type, int protocol);
-SOCKET pgwin32_accept(SOCKET s, struct sockaddr* addr, int* addrlen);
-int pgwin32_connect(SOCKET s, const struct sockaddr* name, int namelen);
-int pgwin32_select(int nfds, fd_set* readfs, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout);
-int pgwin32_recv(SOCKET s, char* buf, int len, int flags);
-int pgwin32_send(SOCKET s, char* buf, int len, int flags);
-
-const char *pgwin32_socket_strerror(int err);
-
-/* in backend/port/win32/security.c */
-extern int pgwin32_is_admin(void);
-extern int pgwin32_is_service(void);
-#endif
-
-
-#define WEXITSTATUS(w)  (((w) >> 8) & 0xff)
-#define WIFEXITED(w)    (((w) & 0xff) == 0)
-#define WIFSIGNALED(w)  (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
-#define WTERMSIG(w)     ((w) & 0x7f)
-
 /* Some extra signals */
 #define SIGHUP                         1
 #define SIGQUIT                                3
 #define SIGTRAP                                5
-#define SIGABRT                                22      /* Set to match W32 value -- not UNIX
-                                                                * value */
+#define SIGABRT                                22      /* Set to match W32 value -- not UNIX value */
 #define SIGKILL                                9
 #define SIGPIPE                                13
 #define SIGALRM                                14
 #define SIGSTOP                                17
+#define SIGTSTP                                18
 #define SIGCONT                                19
 #define SIGCHLD                                20
 #define SIGTTIN                                21
@@ -179,35 +161,45 @@ struct timezone
 
 /* for setitimer in backend/port/win32/timer.c */
 #define ITIMER_REAL 0
-struct itimerval {
+struct itimerval
+{
        struct timeval it_interval;
        struct timeval it_value;
 };
-int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
+int                    setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
 
 
-/* FROM SRA */
-
 /*
  * Supplement to <sys/types.h>.
+ *
+ * Perl already has typedefs for uid_t and gid_t.
  */
-#define uid_t int
-#define gid_t int
-#define pid_t unsigned long
-#define ssize_t int
-#define mode_t int
-#define key_t long
-#define ushort unsigned short
+#ifndef PLPERL_HAVE_UID_GID
+typedef int uid_t;
+typedef int gid_t;
+#endif
+typedef long key_t;
+
+#ifdef WIN32_ONLY_COMPILER
+typedef int pid_t;
+#endif
 
 /*
  * Supplement to <sys/stat.h>.
  */
-#define lstat slat
+#define lstat(path, sb) stat((path), (sb))
+
+/*
+ * Supplement to <fcntl.h>.
+ * This is the same value as _O_NOINHERIT in the MS header file. This is
+ * to ensure that we don't collide with a future definition. It means
+ * we cannot use _O_NOINHERIT ourselves.
+ */
+#define O_DSYNC 0x0080
 
 /*
  * Supplement to <errno.h>.
  */
-#include <errno.h>
 #undef EAGAIN
 #undef EINTR
 #define EINTR WSAEINTR
@@ -222,3 +214,83 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue
 #define ECONNREFUSED WSAECONNREFUSED
 #define EBADFD WSAENOTSOCK
 #define EOPNOTSUPP WSAEOPNOTSUPP
+
+
+/* In backend/port/win32/signal.c */
+extern DLLIMPORT volatile int pg_signal_queue;
+extern DLLIMPORT int pg_signal_mask;
+extern HANDLE pgwin32_signal_event;
+extern HANDLE pgwin32_initial_signal_pipe;
+
+#define UNBLOCKED_SIGNAL_QUEUE()       (pg_signal_queue & ~pg_signal_mask)
+
+
+void           pgwin32_signal_initialize(void);
+HANDLE         pgwin32_create_signal_listener(pid_t pid);
+void           pgwin32_dispatch_queued_signals(void);
+void           pg_queue_signal(int signum);
+
+/* In backend/port/win32/socket.c */
+#ifndef FRONTEND
+#define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
+#define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
+#define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
+#define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
+#define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
+#define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
+
+SOCKET         pgwin32_socket(int af, int type, int protocol);
+SOCKET         pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
+int                    pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
+int                    pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
+int                    pgwin32_recv(SOCKET s, char *buf, int len, int flags);
+int                    pgwin32_send(SOCKET s, char *buf, int len, int flags);
+
+const char *pgwin32_socket_strerror(int err);
+int                    pgwin32_waitforsinglesocket(SOCKET s, int what);
+
+/* in backend/port/win32/security.c */
+extern int     pgwin32_is_admin(void);
+extern int     pgwin32_is_service(void);
+#endif
+
+/* in port/win32error.c */
+extern void _dosmaperr(unsigned long);
+
+
+/* Things that exist in MingW headers, but need to be added to MSVC */
+#ifdef WIN32_ONLY_COMPILER
+typedef long ssize_t;
+typedef unsigned short mode_t;
+
+/*
+ *     Certain "standard edition" versions of MSVC throw a warning
+ *     that later generates an error for "inline" statements, but
+ *     __inline seems to work.  e.g.  Microsoft Visual C++ .NET
+ *     Version 7.1.3088
+ */
+#define inline __inline
+#define __inline__ __inline
+
+#define _S_IRWXU       (_S_IREAD | _S_IWRITE | _S_IEXEC)
+#define _S_IXUSR       _S_IEXEC
+#define _S_IWUSR       _S_IWRITE
+#define _S_IRUSR       _S_IREAD
+#define S_IRUSR                _S_IRUSR
+#define S_IWUSR                _S_IWUSR
+#define S_IXUSR                _S_IXUSR
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+
+#define F_OK 0
+#define W_OK 2
+#define R_OK 4
+
+#define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
+#define isnan(x) _isnan(x)
+#define finite(x) _finite(x)
+
+
+/* Pulled from Makefile.port in mingw */
+#define DLSUFFIX ".dll"
+#endif