]> granicus.if.org Git - postgresql/blob - src/include/port/win32.h
Per discussion earlier today, here is a fix that lets ereport() on win32
[postgresql] / src / include / port / win32.h
1 /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.23 2004/04/22 03:51:24 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 #undef near
11
12 /* Must be here to avoid conflicting with prototype in windows.h */
13 #define mkdir(a,b)      mkdir(a)
14
15
16 #define USES_WINSOCK
17
18 /* defines for dynamic linking on Win32 platform */
19 #if defined(__CYGWIN__) || defined(__MINGW32__)
20
21 #if __GNUC__ && ! defined (__declspec)
22 #error You need egcs 1.1 or newer for compiling!
23 #endif
24
25 #ifdef BUILDING_DLL
26 #define DLLIMPORT __declspec (dllexport)
27 #else                                                   /* not BUILDING_DLL */
28 #define DLLIMPORT __declspec (dllimport)
29 #endif
30
31 #elif defined(WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__))            /* not CYGWIN or MingW */
32
33 #if defined(_DLL)
34 #define DLLIMPORT __declspec (dllexport)
35 #else                                                   /* not _DLL */
36 #define DLLIMPORT __declspec (dllimport)
37 #endif
38
39 #else                                                   /* not CYGWIN, not MSVC, not MingW */
40
41 #define DLLIMPORT
42 #endif
43
44 /*
45  *      IPC defines
46  */
47 #undef HAVE_UNION_SEMUN
48 #define HAVE_UNION_SEMUN 1
49
50 #define IPC_RMID 256
51 #define IPC_CREAT 512
52 #define IPC_EXCL 1024
53 #define IPC_PRIVATE 234564
54 #define IPC_NOWAIT      2048
55 #define IPC_STAT 4096
56
57 #define EACCESS 2048
58 #define EIDRM 4096
59
60 #define SETALL 8192
61 #define GETNCNT 16384
62 #define GETVAL 65536
63 #define SETVAL 131072
64 #define GETPID 262144
65
66 /*
67  *      Shared memory
68  */
69 struct shmid_ds
70 {
71         int                     dummy;
72         int                     shm_nattch;
73 };
74
75 int                     shmdt(const void *shmaddr);
76 void       *shmat(int memId, void *shmaddr, int flag);
77 int                     shmctl(int shmid, int flag, struct shmid_ds * dummy);
78 int                     shmget(int memKey, int size, int flag);
79
80
81 /*
82  *      Semaphores
83  */
84 union semun
85 {
86         int                     val;
87         struct semid_ds *buf;
88         unsigned short *array;
89 };
90
91 struct sembuf
92 {
93         int                     sem_flg;
94         int                     sem_op;
95         int                     sem_num;
96 };
97
98 int                     semctl(int semId, int semNum, int flag, union semun);
99 int                     semget(int semKey, int semNum, int flags);
100 int                     semop(int semId, struct sembuf * sops, int flag);
101
102
103 /* In backend/port/win32/signal.c */
104 void pgwin32_signal_initialize(void);
105 extern DLLIMPORT HANDLE pgwin32_signal_event;
106 void pgwin32_dispatch_queued_signals(void);
107 void pg_queue_signal(int signum);
108
109 #define sigmask(sig) ( 1 << (sig-1) )
110
111 /* Signal function return values */
112 #undef SIG_DFL
113 #undef SIG_ERR
114 #undef SIG_IGN
115 #define SIG_DFL ((pqsigfunc)0)
116 #define SIG_ERR ((pqsigfunc)-1)
117 #define SIG_IGN ((pqsigfunc)1)
118
119 #ifndef FRONTEND
120 #define kill(pid,sig)   pqkill(pid,sig)
121 extern int pqkill(int pid, int sig);
122
123 #define pg_usleep(t) pgwin32_backend_usleep(t)
124 void pgwin32_backend_usleep(long microsec);
125 #endif
126
127 /* In backend/port/win32/socket.c */
128 #ifndef FRONTEND
129 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
130 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
131 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
132 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
133 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
134 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
135
136 SOCKET pgwin32_socket(int af, int type, int protocol);
137 SOCKET pgwin32_accept(SOCKET s, struct sockaddr* addr, int* addrlen);
138 int pgwin32_connect(SOCKET s, const struct sockaddr* name, int namelen);
139 int pgwin32_select(int nfds, fd_set* readfs, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout);
140 int pgwin32_recv(SOCKET s, char* buf, int len, int flags);
141 int pgwin32_send(SOCKET s, char* buf, int len, int flags);
142
143 const char *pgwin32_socket_strerror(int err);
144 #endif
145
146
147 /* Some extra signals */
148 #define SIGHUP                          1
149 #define SIGQUIT                         3
150 #define SIGTRAP                         5
151 #define SIGABRT                         22      /* Set to match W32 value -- not UNIX
152                                                                  * value */
153 #define SIGKILL                         9
154 #define SIGPIPE                         13
155 #define SIGALRM                         14
156 #define SIGSTOP                         17
157 #define SIGCONT                         19
158 #define SIGCHLD                         20
159 #define SIGTTIN                         21
160 #define SIGTTOU                         22      /* Same as SIGABRT -- no problem, I hope */
161 #define SIGWINCH                        28
162 #define SIGUSR1                         30
163 #define SIGUSR2                         31
164
165 struct timezone
166 {
167         int                     tz_minuteswest; /* Minutes west of GMT.  */
168         int                     tz_dsttime;             /* Nonzero if DST is ever in effect.  */
169 };
170
171 /* for setitimer in backend/port/win32/timer.c */
172 #define ITIMER_REAL 0
173 struct itimerval {
174         struct timeval it_interval;
175         struct timeval it_value;
176 };
177 int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
178
179
180 /* FROM SRA */
181
182 /*
183  * Supplement to <sys/types.h>.
184  */
185 #define uid_t int
186 #define gid_t int
187 #define pid_t unsigned long
188 #define ssize_t int
189 #define mode_t int
190 #define key_t long
191 #define ushort unsigned short
192
193 /*
194  * Supplement to <sys/stat.h>.
195  */
196 #define lstat slat
197
198 /*
199  * Supplement to <errno.h>.
200  */
201 #include <errno.h>
202 #undef EAGAIN
203 #undef EINTR
204 #define EINTR WSAEINTR
205 #define EAGAIN WSAEWOULDBLOCK
206 #define EMSGSIZE WSAEMSGSIZE
207 #define EAFNOSUPPORT WSAEAFNOSUPPORT
208 #define EWOULDBLOCK WSAEWOULDBLOCK
209 #define ECONNRESET WSAECONNRESET
210 #define EINPROGRESS WSAEINPROGRESS
211 #define ENOBUFS WSAENOBUFS
212 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
213 #define ECONNREFUSED WSAECONNREFUSED
214 #define EBADFD WSAENOTSOCK
215 #define EOPNOTSUPP WSAEOPNOTSUPP