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