]> granicus.if.org Git - postgresql/blob - src/include/port/win32.h
Replace direct fprintf(stderr) calls by write_stderr(), and cause this
[postgresql] / src / include / port / win32.h
1 /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.26 2004/06/24 21:03:33 tgl 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 pg_usleep(t) pgwin32_backend_usleep(t)
121 void pgwin32_backend_usleep(long microsec);
122 #endif
123
124 /* In backend/port/win32/socket.c */
125 #ifndef FRONTEND
126 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
127 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
128 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
129 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
130 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
131 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
132
133 SOCKET pgwin32_socket(int af, int type, int protocol);
134 SOCKET pgwin32_accept(SOCKET s, struct sockaddr* addr, int* addrlen);
135 int pgwin32_connect(SOCKET s, const struct sockaddr* name, int namelen);
136 int pgwin32_select(int nfds, fd_set* readfs, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout);
137 int pgwin32_recv(SOCKET s, char* buf, int len, int flags);
138 int pgwin32_send(SOCKET s, char* buf, int len, int flags);
139
140 const char *pgwin32_socket_strerror(int err);
141
142 /* in backend/port/win32/security.c */
143 extern int pgwin32_is_admin(void);
144 extern int pgwin32_is_service(void);
145 #endif
146
147
148 /* Some extra signals */
149 #define SIGHUP                          1
150 #define SIGQUIT                         3
151 #define SIGTRAP                         5
152 #define SIGABRT                         22      /* Set to match W32 value -- not UNIX
153                                                                  * value */
154 #define SIGKILL                         9
155 #define SIGPIPE                         13
156 #define SIGALRM                         14
157 #define SIGSTOP                         17
158 #define SIGCONT                         19
159 #define SIGCHLD                         20
160 #define SIGTTIN                         21
161 #define SIGTTOU                         22      /* Same as SIGABRT -- no problem, I hope */
162 #define SIGWINCH                        28
163 #define SIGUSR1                         30
164 #define SIGUSR2                         31
165
166 struct timezone
167 {
168         int                     tz_minuteswest; /* Minutes west of GMT.  */
169         int                     tz_dsttime;             /* Nonzero if DST is ever in effect.  */
170 };
171
172 /* for setitimer in backend/port/win32/timer.c */
173 #define ITIMER_REAL 0
174 struct itimerval {
175         struct timeval it_interval;
176         struct timeval it_value;
177 };
178 int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
179
180
181 /* FROM SRA */
182
183 /*
184  * Supplement to <sys/types.h>.
185  */
186 #define uid_t int
187 #define gid_t int
188 #define pid_t unsigned long
189 #define ssize_t int
190 #define mode_t int
191 #define key_t long
192 #define ushort unsigned short
193
194 /*
195  * Supplement to <sys/stat.h>.
196  */
197 #define lstat slat
198
199 /*
200  * Supplement to <errno.h>.
201  */
202 #include <errno.h>
203 #undef EAGAIN
204 #undef EINTR
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