]> granicus.if.org Git - postgresql/blob - src/include/port/win32.h
Allow Win32 to support the O_SYNC open flag as an wal_sync_method method.
[postgresql] / src / include / port / win32.h
1 /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.43 2005/02/27 00:53:29 momjian Exp $ */
2
3 /* undefine and redefine after #include */
4 #undef mkdir
5
6 #undef ERROR
7 #include <windows.h>
8 #include <winsock.h>
9 #include <process.h>
10 #include <signal.h>
11 #include <errno.h>
12
13 #undef near
14
15 /* Must be here to avoid conflicting with prototype in windows.h */
16 #define mkdir(a,b)      mkdir(a)
17
18
19 #define fsync(a)        _commit(a)
20 #define ftruncate(a,b)  chsize(a,b)
21
22 #define USES_WINSOCK
23
24 /* defines for dynamic linking on Win32 platform */
25 #if defined(__MINGW32__) || defined(__CYGWIN__)
26
27 #if __GNUC__ && ! defined (__declspec)
28 #error You need egcs 1.1 or newer for compiling!
29 #endif
30
31 #ifdef BUILDING_DLL
32 #define DLLIMPORT __declspec (dllexport)
33 #else                                                   /* not BUILDING_DLL */
34 #define DLLIMPORT __declspec (dllimport)
35 #endif
36
37 #elif defined(WIN32_CLIENT_ONLY)
38
39 #if defined(_DLL)
40 #define DLLIMPORT __declspec (dllexport)
41 #else                                                   /* not _DLL */
42 #define DLLIMPORT __declspec (dllimport)
43 #endif
44
45 #else                                                   /* not CYGWIN, not MSVC, not MingW */
46
47 #define DLLIMPORT
48 #endif
49
50 /*
51  *      IPC defines
52  */
53 #undef HAVE_UNION_SEMUN
54 #define HAVE_UNION_SEMUN 1
55
56 #define IPC_RMID 256
57 #define IPC_CREAT 512
58 #define IPC_EXCL 1024
59 #define IPC_PRIVATE 234564
60 #define IPC_NOWAIT      2048
61 #define IPC_STAT 4096
62
63 #define EACCESS 2048
64 #define EIDRM 4096
65
66 #define SETALL 8192
67 #define GETNCNT 16384
68 #define GETVAL 65536
69 #define SETVAL 131072
70 #define GETPID 262144
71
72 /*
73  *      Shared memory
74  */
75 struct shmid_ds
76 {
77         int                     dummy;
78         int                     shm_nattch;
79 };
80
81 int                     shmdt(const void *shmaddr);
82 void       *shmat(int memId, void *shmaddr, int flag);
83 int                     shmctl(int shmid, int flag, struct shmid_ds * dummy);
84 int                     shmget(int memKey, int size, int flag);
85
86
87 /*
88  *      Semaphores
89  */
90 union semun
91 {
92         int                     val;
93         struct semid_ds *buf;
94         unsigned short *array;
95 };
96
97 struct sembuf
98 {
99         int                     sem_flg;
100         int                     sem_op;
101         int                     sem_num;
102 };
103
104 int                     semctl(int semId, int semNum, int flag, union semun);
105 int                     semget(int semKey, int semNum, int flags);
106 int                     semop(int semId, struct sembuf * sops, int flag);
107
108
109 /*
110  * Signal stuff
111  */
112 #define WEXITSTATUS(w)  (((w) >> 8) & 0xff)
113 #define WIFEXITED(w)    (((w) & 0xff) == 0)
114 #define WIFSIGNALED(w)  (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
115 #define WTERMSIG(w)             ((w) & 0x7f)
116
117 #define sigmask(sig) ( 1 << ((sig)-1) )
118
119 /* Signal function return values */
120 #undef SIG_DFL
121 #undef SIG_ERR
122 #undef SIG_IGN
123 #define SIG_DFL ((pqsigfunc)0)
124 #define SIG_ERR ((pqsigfunc)-1)
125 #define SIG_IGN ((pqsigfunc)1)
126
127 /* Some extra signals */
128 #define SIGHUP                          1
129 #define SIGQUIT                         3
130 #define SIGTRAP                         5
131 #define SIGABRT                         22      /* Set to match W32 value -- not UNIX
132                                                                  * value */
133 #define SIGKILL                         9
134 #define SIGPIPE                         13
135 #define SIGALRM                         14
136 #define SIGSTOP                         17
137 #define SIGTSTP                         18
138 #define SIGCONT                         19
139 #define SIGCHLD                         20
140 #define SIGTTIN                         21
141 #define SIGTTOU                         22      /* Same as SIGABRT -- no problem, I hope */
142 #define SIGWINCH                        28
143 #define SIGUSR1                         30
144 #define SIGUSR2                         31
145
146 struct timezone
147 {
148         int                     tz_minuteswest; /* Minutes west of GMT.  */
149         int                     tz_dsttime;             /* Nonzero if DST is ever in effect.  */
150 };
151
152 /* for setitimer in backend/port/win32/timer.c */
153 #define ITIMER_REAL 0
154 struct itimerval
155 {
156         struct timeval it_interval;
157         struct timeval it_value;
158 };
159 int                     setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
160
161
162 /*
163  * Supplement to <sys/types.h>.
164  *
165  * Perl already has conflicting defines for uid_t and gid_t.
166  */
167 #ifndef PLPERL_HAVE_UID_GID
168 typedef int uid_t;
169 typedef int gid_t;
170 #else
171 /* These are redefined by perl. */
172 #define uid_t int
173 #define gid_t int
174 #endif
175 typedef long key_t;
176
177 #ifdef WIN32_CLIENT_ONLY
178 typedef int pid_t;
179 #endif
180
181 /*
182  * Supplement to <sys/stat.h>.
183  */
184 #define lstat(path, sb) stat((path), (sb))
185
186 /*
187  * Supplement to <fcntl.h>.
188  * This is the same value as _O_NOINHERIT in the MS header file. This is
189  * to ensure that we don't collide with a future definition. It means
190  * we cannot use _O_NOINHERIT ourselves.
191  */
192 #define O_SYNC 0x0080
193
194 /*
195  * Supplement to <errno.h>.
196  */
197 #undef EAGAIN
198 #undef EINTR
199 #define EINTR WSAEINTR
200 #define EAGAIN WSAEWOULDBLOCK
201 #define EMSGSIZE WSAEMSGSIZE
202 #define EAFNOSUPPORT WSAEAFNOSUPPORT
203 #define EWOULDBLOCK WSAEWOULDBLOCK
204 #define ECONNRESET WSAECONNRESET
205 #define EINPROGRESS WSAEINPROGRESS
206 #define ENOBUFS WSAENOBUFS
207 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
208 #define ECONNREFUSED WSAECONNREFUSED
209 #define EBADFD WSAENOTSOCK
210 #define EOPNOTSUPP WSAEOPNOTSUPP
211
212
213 /* In backend/port/win32/signal.c */
214 extern DLLIMPORT HANDLE pgwin32_signal_event;
215 extern HANDLE pgwin32_initial_signal_pipe;
216
217 void            pgwin32_signal_initialize(void);
218 HANDLE          pgwin32_create_signal_listener(pid_t pid);
219 void            pgwin32_dispatch_queued_signals(void);
220 void            pg_queue_signal(int signum);
221
222 #ifndef FRONTEND
223 #define pg_usleep(t) pgwin32_backend_usleep(t)
224 void            pgwin32_backend_usleep(long microsec);
225 #endif
226
227 /* In backend/port/win32/socket.c */
228 #ifndef FRONTEND
229 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
230 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
231 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
232 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
233 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
234 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
235
236 SOCKET          pgwin32_socket(int af, int type, int protocol);
237 SOCKET          pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
238 int                     pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
239 int                     pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
240 int                     pgwin32_recv(SOCKET s, char *buf, int len, int flags);
241 int                     pgwin32_send(SOCKET s, char *buf, int len, int flags);
242
243 const char *pgwin32_socket_strerror(int err);
244 int pgwin32_waitforsinglesocket(SOCKET s, int what);
245
246 /* in backend/port/win32/security.c */
247 extern int      pgwin32_is_admin(void);
248 extern int      pgwin32_is_service(void);
249 #endif
250
251 /* in backend/port/win32/error.c */
252 extern void _dosmaperr(unsigned long);