]> granicus.if.org Git - postgresql/blobdiff - src/include/port/win32.h
Remove dead code in win32.h.
[postgresql] / src / include / port / win32.h
index d1789b25265754ca68a6e79b82679c9e745f4298..c9390d11247096598b2dbc36fb3c0d38348fe754 100644 (file)
@@ -1,17 +1,42 @@
-/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.71 2007/01/25 21:50:49 momjian Exp $ */
+/* src/include/port/win32.h */
 
 #if defined(_MSC_VER) || defined(__BORLANDC__)
 #define WIN32_ONLY_COMPILER
 #endif
 
+/*
+ * Make sure _WIN32_WINNT has the minimum required value.
+ * Leave a higher value in place.
+*/
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
+#undef _WIN32_WINNT
+#endif
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
+/*
+ * Always build with SSPI support. Keep it as a #define in case
+ * we want a switch to disable it sometime in the future.
+ */
+#ifndef __BORLANDC__
+#define ENABLE_SSPI 1
+#endif
+
 /* undefine and redefine after #include */
 #undef mkdir
 
 #undef ERROR
+
+/*
+ * The Mingw64 headers choke if this is already defined - they
+ * define it themselves.
+ */
+#if !defined(__MINGW64_VERSION_MAJOR) || defined(WIN32_ONLY_COMPILER)
 #define _WINSOCKAPI_
-#include <windows.h>
+#endif
 #include <winsock2.h>
 #include <ws2tcpip.h>
+#include <windows.h>
 #undef small
 #include <process.h>
 #include <signal.h>
 /* Must be here to avoid conflicting with prototype in windows.h */
 #define mkdir(a,b)     mkdir(a)
 
-#define HAVE_FSYNC_WRITETHROUGH
-#define HAVE_FSYNC_WRITETHROUGH_ONLY
 #define ftruncate(a,b) chsize(a,b)
+
+/* Windows doesn't have fsync() as such, use _commit() */
+#define fsync(fd) _commit(fd)
+
 /*
- *     Even though we don't support 'fsync' as a wal_sync_method,
- *     we do fsync() a few other places where _commit() is just fine.
+ * For historical reasons, we allow setting wal_sync_method to
+ * fsync_writethrough on Windows, even though it's really identical to fsync
+ * (both code paths wind up at _commit()).
  */
-#define fsync(fd) _commit(fd)
+#define HAVE_FSYNC_WRITETHROUGH
+#define FSYNC_WRITETHROUGH_IS_FSYNC
 
 #define USES_WINSOCK
 
-/* defines for dynamic linking on Win32 platform */
-#if defined(WIN32) || defined(__CYGWIN__)
+/* defines for dynamic linking on Win32 platform
+ *
+ *     http://support.microsoft.com/kb/132044
+ *     http://msdn.microsoft.com/en-us/library/8fskxacy(v=vs.80).aspx
+ *     http://msdn.microsoft.com/en-us/library/a90k134d(v=vs.80).aspx
+ */
 
-#if __GNUC__ && ! defined (__declspec)
-#error You need egcs 1.1 or newer for compiling!
-#endif
+#if defined(WIN32) || defined(__CYGWIN__)
 
 #ifdef BUILDING_DLL
-#define DLLIMPORT __declspec (dllexport)
+#define PGDLLIMPORT __declspec (dllexport)
 #else                                                  /* not BUILDING_DLL */
-#define DLLIMPORT __declspec (dllimport)
+#define PGDLLIMPORT __declspec (dllimport)
 #endif
-#else                                                  /* not CYGWIN, not MSVC, not MingW */
 
-#define DLLIMPORT
+#ifdef _MSC_VER
+#define PGDLLEXPORT __declspec (dllexport)
+#else
+#define PGDLLEXPORT
+#endif
+#else                                                  /* not CYGWIN, not MSVC, not MingW */
+#define PGDLLIMPORT
+#define PGDLLEXPORT
 #endif
 
 
 #define IPC_STAT 4096
 
 #define EACCESS 2048
+#ifndef EIDRM
 #define EIDRM 4096
+#endif
 
 #define SETALL 8192
 #define GETNCNT 16384
 #define SETVAL 131072
 #define GETPID 262144
 
-/*
- *     Shared memory
- */
-struct shmid_ds
-{
-       int                     dummy;
-       int                     shm_nattch;
-};
-
-int                    shmdt(const void *shmaddr);
-void      *shmat(int memId, void *shmaddr, int flag);
-int                    shmctl(int shmid, int flag, struct shmid_ds * dummy);
-int                    shmget(int memKey, int size, int flag);
-
-
-/*
- *     Semaphores
- */
-union semun
-{
-       int                     val;
-       struct semid_ds *buf;
-       unsigned short *array;
-};
-
-struct sembuf
-{
-       int                     sem_flg;
-       int                     sem_op;
-       int                     sem_num;
-};
-
-int                    semctl(int semId, int semNum, int flag, union semun);
-int                    semget(int semKey, int semNum, int flags);
-int                    semop(int semId, struct sembuf * sops, int flag);
-
 
 /*
  *     Signal stuff
@@ -153,17 +156,17 @@ int                       semop(int semId, struct sembuf * sops, int flag);
  *             example, the code for the all-too-familiar STATUS_ACCESS_VIOLATION is
  *             0xC0000005. A more complete set of exception codes can be found in
  *             NTSTATUS.H from the Windows NT DDK.
- *                                               
+ *
  *     Some day we might want to print descriptions for the most common
  *     exceptions, rather than printing an include file name.  We could use
  *     RtlNtStatusToDosError() and pass to FormatMessage(), which can print
  *     the text of error values, but MinGW does not support
  *     RtlNtStatusToDosError().
  */
-#define WIFEXITED(w)    (((w) & 0XFFFFFF00) == 0)
-#define WIFSIGNALED(w)  (!WIFEXITED(w))
-#define WEXITSTATUS(w)  (w)
-#define WTERMSIG(w)     (w)
+#define WIFEXITED(w)   (((w) & 0XFFFFFF00) == 0)
+#define WIFSIGNALED(w) (!WIFEXITED(w))
+#define WEXITSTATUS(w) (w)
+#define WTERMSIG(w)            (w)
 
 #define sigmask(sig) ( 1 << ((sig)-1) )
 
@@ -195,11 +198,17 @@ int                       semop(int semId, struct sembuf * sops, int flag);
 #define SIGUSR2                                31
 #endif
 
+/*
+ * New versions of mingw have gettimeofday() and also declare
+ * struct timezone to support it.
+ */
+#ifndef HAVE_GETTIMEOFDAY
 struct timezone
 {
        int                     tz_minuteswest; /* Minutes west of GMT.  */
        int                     tz_dsttime;             /* Nonzero if DST is ever in effect.  */
 };
+#endif
 
 /* for setitimer in backend/port/win32/timer.c */
 #define ITIMER_REAL 0
@@ -208,8 +217,25 @@ struct itimerval
        struct timeval it_interval;
        struct timeval it_value;
 };
+
 int                    setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
 
+/*
+ * WIN32 does not provide 64-bit off_t, but does provide the functions operating
+ * with 64-bit offsets.
+ */
+#define pgoff_t __int64
+#ifdef WIN32_ONLY_COMPILER
+#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
+#define ftello(stream) _ftelli64(stream)
+#else
+#ifndef fseeko
+#define fseeko(stream, offset, origin) fseeko64(stream, offset, origin)
+#endif
+#ifndef ftello
+#define ftello(stream) ftello64(stream)
+#endif
+#endif
 
 /*
  * Supplement to <sys/types.h>.
@@ -241,26 +267,76 @@ typedef int pid_t;
 
 /*
  * Supplement to <errno.h>.
+ *
+ * We redefine network-related Berkeley error symbols as the corresponding WSA
+ * constants.  This allows elog.c to recognize them as being in the Winsock
+ * error code range and pass them off to pgwin32_socket_strerror(), since
+ * Windows' version of plain strerror() won't cope.  Note that this will break
+ * if these names are used for anything else besides Windows Sockets errors.
+ * See TranslateSocketError() when changing this list.
  */
 #undef EAGAIN
+#define EAGAIN WSAEWOULDBLOCK
 #undef EINTR
 #define EINTR WSAEINTR
-#define EAGAIN WSAEWOULDBLOCK
+#undef EMSGSIZE
 #define EMSGSIZE WSAEMSGSIZE
+#undef EAFNOSUPPORT
 #define EAFNOSUPPORT WSAEAFNOSUPPORT
+#undef EWOULDBLOCK
 #define EWOULDBLOCK WSAEWOULDBLOCK
+#undef ECONNRESET
 #define ECONNRESET WSAECONNRESET
+#undef EINPROGRESS
 #define EINPROGRESS WSAEINPROGRESS
+#undef ENOBUFS
 #define ENOBUFS WSAENOBUFS
+#undef EPROTONOSUPPORT
 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
+#undef ECONNREFUSED
 #define ECONNREFUSED WSAECONNREFUSED
+#undef EBADFD
 #define EBADFD WSAENOTSOCK
+#undef EOPNOTSUPP
 #define EOPNOTSUPP WSAEOPNOTSUPP
 
+/*
+ * Extended locale functions with gratuitous underscore prefixes.
+ * (These APIs are nevertheless fully documented by Microsoft.)
+ */
+#define locale_t _locale_t
+#define tolower_l _tolower_l
+#define toupper_l _toupper_l
+#define towlower_l _towlower_l
+#define towupper_l _towupper_l
+#define isdigit_l _isdigit_l
+#define iswdigit_l _iswdigit_l
+#define isalpha_l _isalpha_l
+#define iswalpha_l _iswalpha_l
+#define isalnum_l _isalnum_l
+#define iswalnum_l _iswalnum_l
+#define isupper_l _isupper_l
+#define iswupper_l _iswupper_l
+#define islower_l _islower_l
+#define iswlower_l _iswlower_l
+#define isgraph_l _isgraph_l
+#define iswgraph_l _iswgraph_l
+#define isprint_l _isprint_l
+#define iswprint_l _iswprint_l
+#define ispunct_l _ispunct_l
+#define iswpunct_l _iswpunct_l
+#define isspace_l _isspace_l
+#define iswspace_l _iswspace_l
+#define strcoll_l _strcoll_l
+#define strxfrm_l _strxfrm_l
+#define wcscoll_l _wcscoll_l
+#define wcstombs_l _wcstombs_l
+#define mbstowcs_l _mbstowcs_l
+
 
 /* In backend/port/win32/signal.c */
-extern DLLIMPORT volatile int pg_signal_queue;
-extern DLLIMPORT int pg_signal_mask;
+extern PGDLLIMPORT volatile int pg_signal_queue;
+extern PGDLLIMPORT int pg_signal_mask;
 extern HANDLE pgwin32_signal_event;
 extern HANDLE pgwin32_initial_signal_pipe;
 
@@ -275,6 +351,8 @@ 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 bind(s, addr, addrlen) pgwin32_bind(s, addr, addrlen)
+#define listen(s, backlog) pgwin32_listen(s, backlog)
 #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)
@@ -282,74 +360,101 @@ void             pg_queue_signal(int signum);
 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
 
 SOCKET         pgwin32_socket(int af, int type, int protocol);
+int                    pgwin32_bind(SOCKET s, struct sockaddr * addr, int addrlen);
+int                    pgwin32_listen(SOCKET s, int backlog);
 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);
+int                    pgwin32_send(SOCKET s, const void *buf, int len, int flags);
 
 const char *pgwin32_socket_strerror(int err);
-int                    pgwin32_waitforsinglesocket(SOCKET s, int what);
+int                    pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
+
+extern int     pgwin32_noblock;
 
-/* in backend/port/win32/security.c */
-extern int     pgwin32_is_admin(void);
-extern int     pgwin32_is_service(void);
 #endif
 
+/* in backend/port/win32_shmem.c */
+extern int     pgwin32_ReserveSharedMemoryRegion(HANDLE);
+
+/* in backend/port/win32/crashdump.c */
+extern void pgwin32_install_crashdump_handler(void);
+
 /* in port/win32error.c */
 extern void _dosmaperr(unsigned long);
 
+/* in port/win32env.c */
+extern int     pgwin32_putenv(const char *);
+extern void pgwin32_unsetenv(const char *);
+
+/* in port/win32security.c */
+extern int     pgwin32_is_service(void);
+extern int     pgwin32_is_admin(void);
+
+#define putenv(x) pgwin32_putenv(x)
+#define unsetenv(x) pgwin32_unsetenv(x)
 
-/* Things that exist in MingW headers, but need to be added to MSVC */
+/* Things that exist in MingW headers, but need to be added to MSVC & BCC */
 #ifdef WIN32_ONLY_COMPILER
-#ifndef __BORLANDC__
+
+#ifndef _WIN64
 typedef long ssize_t;
-typedef unsigned short mode_t;
+#else
+typedef __int64 ssize_t;
 #endif
 
-/*
- *     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
-
 #ifndef __BORLANDC__
-#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
+typedef unsigned short mode_t;
+
+#define S_IRUSR _S_IREAD
+#define S_IWUSR _S_IWRITE
+#define S_IXUSR _S_IEXEC
+#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
+/* see also S_IRGRP etc below */
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
-#endif
+#endif   /* __BORLANDC__ */
 
 #define F_OK 0
 #define W_OK 2
 #define R_OK 4
 
+#if (_MSC_VER < 1800)
 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
 #define isnan(x) _isnan(x)
-
-#ifndef                        BIG_ENDIAN
-#define                        BIG_ENDIAN              4321
-#endif
-#ifndef                        LITTLE_ENDIAN
-#define                        LITTLE_ENDIAN   1234
-#endif
-#ifndef                        PDP_ENDIAN
-#define                        PDP_ENDIAN              3412
-#endif
-
-#ifndef BYTE_ORDER
-#define BYTE_ORDER LITTLE_ENDIAN
 #endif
 
 /* Pulled from Makefile.port in mingw */
 #define DLSUFFIX ".dll"
 
+#ifdef __BORLANDC__
+
+/* for port/dirent.c */
+#ifndef INVALID_FILE_ATTRIBUTES
+#define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
 #endif
+
+/* for port/open.c */
+#ifndef O_RANDOM
+#define O_RANDOM               0x0010  /* File access is primarily random */
+#define O_SEQUENTIAL   0x0020  /* File access is primarily sequential */
+#define O_TEMPORARY            0x0040  /* Temporary file bit */
+#define O_SHORT_LIVED  0x1000  /* Temporary storage file, try not to flush */
+#define _O_SHORT_LIVED O_SHORT_LIVED
+#endif   /* ifndef O_RANDOM */
+#endif   /* __BORLANDC__ */
+#endif   /* WIN32_ONLY_COMPILER */
+
+/* These aren't provided by either MingW or MSVC */
+#ifndef __BORLANDC__
+#define S_IRGRP 0
+#define S_IWGRP 0
+#define S_IXGRP 0
+#define S_IRWXG 0
+#define S_IROTH 0
+#define S_IWOTH 0
+#define S_IXOTH 0
+#define S_IRWXO 0
+
+#endif   /* __BORLANDC__ */