1 /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.61 2006/10/03 20:33:20 tgl Exp $ */
3 #if defined(_MSC_VER) || defined(__BORLANDC__)
4 #define WIN32_ONLY_COMPILER
7 /* undefine and redefine after #include */
20 #include <sys/utime.h> /* for non-unicode version */
23 /* Must be here to avoid conflicting with prototype in windows.h */
24 #define mkdir(a,b) mkdir(a)
26 #define HAVE_FSYNC_WRITETHROUGH
27 #define HAVE_FSYNC_WRITETHROUGH_ONLY
28 #define ftruncate(a,b) chsize(a,b)
30 * Even though we don't support 'fsync' as a wal_sync_method,
31 * we do fsync() a few other places where _commit() is just fine.
33 #define fsync(fd) _commit(fd)
37 /* defines for dynamic linking on Win32 platform */
38 #if defined(WIN32) || defined(__CYGWIN__)
40 #if __GNUC__ && ! defined (__declspec)
41 #error You need egcs 1.1 or newer for compiling!
45 #define DLLIMPORT __declspec (dllexport)
46 #else /* not BUILDING_DLL */
47 #define DLLIMPORT __declspec (dllimport)
50 #else /* not CYGWIN, not MSVC, not MingW */
59 #undef HAVE_UNION_SEMUN
60 #define HAVE_UNION_SEMUN 1
65 #define IPC_PRIVATE 234564
66 #define IPC_NOWAIT 2048
87 int shmdt(const void *shmaddr);
88 void *shmat(int memId, void *shmaddr, int flag);
89 int shmctl(int shmid, int flag, struct shmid_ds * dummy);
90 int shmget(int memKey, int size, int flag);
100 unsigned short *array;
110 int semctl(int semId, int semNum, int flag, union semun);
111 int semget(int semKey, int semNum, int flags);
112 int semop(int semId, struct sembuf * sops, int flag);
117 * WIN32 doesn't have wait(), so the return value for children
118 * is simply the return value specified by the child, without
119 * any additional information on whether the child terminated
120 * on its own or via a signal. These macros are also used
121 * to interpret the return value of system().
123 #define WEXITSTATUS(w) (w)
124 #define WIFEXITED(w) (true)
125 #define WIFSIGNALED(w) (false)
126 #define WTERMSIG(w) (0)
128 #define sigmask(sig) ( 1 << ((sig)-1) )
130 /* Signal function return values */
134 #define SIG_DFL ((pqsigfunc)0)
135 #define SIG_ERR ((pqsigfunc)-1)
136 #define SIG_IGN ((pqsigfunc)1)
138 /* Some extra signals */
142 #define SIGABRT 22 /* Set to match W32 value -- not UNIX value */
151 #define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */
158 int tz_minuteswest; /* Minutes west of GMT. */
159 int tz_dsttime; /* Nonzero if DST is ever in effect. */
162 /* for setitimer in backend/port/win32/timer.c */
163 #define ITIMER_REAL 0
166 struct timeval it_interval;
167 struct timeval it_value;
169 int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
173 * Supplement to <sys/types.h>.
175 * Perl already has typedefs for uid_t and gid_t.
177 #ifndef PLPERL_HAVE_UID_GID
183 #ifdef WIN32_ONLY_COMPILER
188 * Supplement to <sys/stat.h>.
190 #define lstat(path, sb) stat((path), (sb))
193 * Supplement to <fcntl.h>.
194 * This is the same value as _O_NOINHERIT in the MS header file. This is
195 * to ensure that we don't collide with a future definition. It means
196 * we cannot use _O_NOINHERIT ourselves.
198 #define O_DSYNC 0x0080
201 * Supplement to <errno.h>.
205 #define EINTR WSAEINTR
206 #define EAGAIN WSAEWOULDBLOCK
207 #define EMSGSIZE WSAEMSGSIZE
208 #define EAFNOSUPPORT WSAEAFNOSUPPORT
209 #define EWOULDBLOCK WSAEWOULDBLOCK
210 #define ECONNRESET WSAECONNRESET
211 #define EINPROGRESS WSAEINPROGRESS
212 #define ENOBUFS WSAENOBUFS
213 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
214 #define ECONNREFUSED WSAECONNREFUSED
215 #define EBADFD WSAENOTSOCK
216 #define EOPNOTSUPP WSAEOPNOTSUPP
219 /* In backend/port/win32/signal.c */
220 extern DLLIMPORT volatile int pg_signal_queue;
221 extern DLLIMPORT int pg_signal_mask;
222 extern HANDLE pgwin32_signal_event;
223 extern HANDLE pgwin32_initial_signal_pipe;
225 #define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask)
228 void pgwin32_signal_initialize(void);
229 HANDLE pgwin32_create_signal_listener(pid_t pid);
230 void pgwin32_dispatch_queued_signals(void);
231 void pg_queue_signal(int signum);
233 /* In backend/port/win32/socket.c */
235 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
236 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
237 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
238 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
239 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
240 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
242 SOCKET pgwin32_socket(int af, int type, int protocol);
243 SOCKET pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
244 int pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
245 int pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
246 int pgwin32_recv(SOCKET s, char *buf, int len, int flags);
247 int pgwin32_send(SOCKET s, char *buf, int len, int flags);
249 const char *pgwin32_socket_strerror(int err);
250 int pgwin32_waitforsinglesocket(SOCKET s, int what);
252 /* in backend/port/win32/security.c */
253 extern int pgwin32_is_admin(void);
254 extern int pgwin32_is_service(void);
257 /* in port/win32error.c */
258 extern void _dosmaperr(unsigned long);
261 /* Things that exist in MingW headers, but need to be added to MSVC */
262 #ifdef WIN32_ONLY_COMPILER
263 typedef long ssize_t;
264 typedef unsigned short mode_t;
267 * Certain "standard edition" versions of MSVC throw a warning
268 * that later generates an error for "inline" statements, but
269 * __inline seems to work. e.g. Microsoft Visual C++ .NET
272 #define inline __inline
273 #define __inline__ __inline
275 #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
276 #define _S_IXUSR _S_IEXEC
277 #define _S_IWUSR _S_IWRITE
278 #define _S_IRUSR _S_IREAD
279 #define S_IRUSR _S_IRUSR
280 #define S_IWUSR _S_IWUSR
281 #define S_IXUSR _S_IXUSR
282 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
283 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
289 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
290 #define isnan(x) _isnan(x)
291 #define finite(x) _finite(x)
294 /* Pulled from Makefile.port in mingw */
295 #define DLSUFFIX ".dll"