lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / sal / osl / unx / system.hxx
blob57c418070a737ef510dbc706276a64268e5eec15
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SAL_OSL_UNX_SYSTEM_HXX
21 #define INCLUDED_SAL_OSL_UNX_SYSTEM_HXX
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <limits.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <stdarg.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <dirent.h>
33 #include <signal.h>
34 #include <utime.h>
36 #include <pwd.h>
38 #include <netdb.h>
40 #include <sys/stat.h>
41 #include <sys/wait.h>
43 #include <sys/types.h>
45 /* Make sockets of type AF_UNIX use underlying FS rights */
46 #if defined(__sun) && !defined(_XOPEN_SOURCE)
47 # define _XOPEN_SOURCE 500
48 # include <sys/socket.h>
49 # undef _XOPEN_SOURCE
50 #else
51 # include <sys/socket.h>
52 #endif
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
57 #ifdef SYSV
58 # include <sys/utsname.h>
59 #endif
61 #ifdef LINUX
62 # ifndef __USE_GNU
63 # define __USE_GNU
64 # endif
66 # include <shadow.h>
67 # include <pthread.h>
68 # include <sys/file.h>
69 # include <sys/ioctl.h>
70 # include <sys/uio.h>
71 # include <sys/un.h>
72 # include <netinet/tcp.h>
73 # include <dlfcn.h>
74 # include <endian.h>
75 # include <sys/time.h>
76 # define IORESOURCE_TRANSFER_BSD
77 # define IOCHANNEL_TRANSFER_BSD_RENO
78 # define pthread_testcancel()
79 # define NO_PTHREAD_PRIORITY
80 # define PTHREAD_SIGACTION pthread_sigaction
82 # ifndef ETIME
83 # define ETIME ETIMEDOUT
84 # endif
86 #endif
88 #ifdef HAIKU
89 # include <shadow.h>
90 # include <pthread.h>
91 # include <sys/file.h>
92 # include <sys/ioctl.h>
93 # include <sys/uio.h>
94 # include <sys/un.h>
95 # include <netinet/tcp.h>
96 # include <dlfcn.h>
97 # include <endian.h>
98 # include <sys/time.h>
99 # define IORESOURCE_TRANSFER_BSD
100 # define IOCHANNEL_TRANSFER_BSD_RENO
101 # define pthread_testcancel()
102 # define NO_PTHREAD_PRIORITY
103 # define NO_PTHREAD_RTL
104 # define PTHREAD_SIGACTION pthread_sigaction
106 # ifndef ETIME
107 # define ETIME ETIMEDOUT
108 # endif
109 # define SIGIOT SIGABRT
110 # define SOCK_RDM 0
111 // hack: Haiku defines SOL_SOCKET as -1, but this makes GCC complain about
112 // narrowing conversion
113 # undef SOL_SOCKET
114 # define SOL_SOCKET (sal_uInt32) -1
116 #endif
118 #if defined(ANDROID)
119 # include <pthread.h>
120 # include <sys/file.h>
121 # include <sys/ioctl.h>
122 # include <sys/uio.h>
123 # include <sys/un.h>
124 # include <netinet/tcp.h>
125 # include <dlfcn.h>
126 # include <endian.h>
127 # include <sys/time.h>
128 # define IORESOURCE_TRANSFER_BSD
129 # define IOCHANNEL_TRANSFER_BSD_RENO
130 # define pthread_testcancel()
131 # define NO_PTHREAD_PRIORITY
132 #endif
134 #ifdef NETBSD
135 # define NO_PTHREAD_RTL
136 #endif
138 #ifdef FREEBSD
139 # define ETIME ETIMEDOUT
140 # include <pthread.h>
141 # include <sys/sem.h>
142 # include <dlfcn.h>
143 # include <sys/filio.h>
144 # include <sys/ioctl.h>
145 # include <sys/param.h>
146 # include <sys/time.h>
147 # include <sys/uio.h>
148 # include <sys/exec.h>
149 # include <vm/vm.h>
150 # include <vm/vm_param.h>
151 # include <vm/pmap.h>
152 # include <vm/swap_pager.h>
153 # include <sys/un.h>
154 # include <netinet/tcp.h>
155 # define IORESOURCE_TRANSFER_BSD
156 # include <machine/endian.h>
157 # define NO_PTHREAD_RTL
158 #endif
160 #ifdef OPENBSD
161 # define ETIME ETIMEDOUT
162 # include <pthread.h>
163 # include <sys/sem.h>
164 # include <dlfcn.h>
165 # include <sys/filio.h>
166 # include <sys/ioctl.h>
167 # include <sys/param.h>
168 # include <sys/time.h>
169 # include <sys/uio.h>
170 # include <sys/exec.h>
171 # include <sys/un.h>
172 # include <netinet/tcp.h>
173 # define IORESOURCE_TRANSFER_BSD
174 # include <machine/endian.h>
175 # define PTR_SIZE_T(s) ((size_t *)&(s))
176 # define IORESOURCE_TRANSFER_BSD
177 # define IOCHANNEL_TRANSFER_BSD_RENO
178 # define pthread_testcancel()
179 # define NO_PTHREAD_PRIORITY
180 # define NO_PTHREAD_RTL
181 # define PTHREAD_SIGACTION pthread_sigaction
182 #endif
184 #if defined(DRAGONFLY) || defined(NETBSD)
185 # define ETIME ETIMEDOUT
186 # include <pthread.h>
187 # include <sys/sem.h>
188 # include <dlfcn.h>
189 # include <sys/filio.h>
190 # include <sys/ioctl.h>
191 # include <sys/param.h>
192 # include <sys/time.h>
193 # include <sys/uio.h>
194 # include <sys/exec.h>
195 # include <sys/un.h>
196 # include <netinet/tcp.h>
197 # include <machine/endian.h>
198 # define IORESOURCE_TRANSFER_BSD
199 # define IOCHANNEL_TRANSFER_BSD_RENO
200 #endif
202 #ifdef AIX
203 # define AF_IPX -1
204 # include <strings.h>
205 # include <pthread.h>
206 # include <dlfcn.h>
207 # include <sys/time.h>
208 # include <sys/un.h>
209 # include <netinet/tcp.h>
210 # include <sys/machine.h>
211 # define SLEEP_TIMESPEC(timespec) nsleep(&timespec, 0)
212 # define LIBPATH "LIBPATH"
213 #endif
215 #ifdef __sun
216 # include <shadow.h>
217 # include <sys/un.h>
218 # include <stropts.h>
219 # include <pthread.h>
220 # include <netinet/tcp.h>
221 # include <sys/filio.h>
222 # include <dlfcn.h>
223 # include <sys/isa_defs.h>
224 # define IORESOURCE_TRANSFER_SYSV
225 # define IOCHANNEL_TRANSFER_BSD
226 # define LIBPATH "LD_LIBRARY_PATH"
227 #endif
229 #ifdef MACOSX
230 #define TimeValue CFTimeValue // Do not conflict with TimeValue in sal/inc/osl/time.h
231 #include <Carbon/Carbon.h>
232 #undef TimeValue
233 # ifndef ETIME
234 # define ETIME ETIMEDOUT
235 # endif
236 # include <dlfcn.h>
237 # include <pthread.h>
238 # include <sys/file.h>
239 # include <sys/ioctl.h>
240 # include <sys/uio.h>
241 # include <sys/un.h>
242 # include <netinet/tcp.h>
243 # include <machine/endian.h>
244 # include <sys/time.h>
245 # include <mach-o/dyld.h>
246 # define IOCHANNEL_TRANSFER_BSD_RENO
247 # define NO_PTHREAD_RTL
248 /* for NSGetArgc/Argv/Environ */
249 # include <crt_externs.h>
250 int macxp_resolveAlias(char *path, int buflen);
251 #endif
253 #ifdef IOS
254 # ifndef ETIME
255 # define ETIME ETIMEDOUT
256 # endif
257 # include <dlfcn.h>
258 # include <pthread.h>
259 # include <sys/file.h>
260 # include <sys/ioctl.h>
261 # include <sys/uio.h>
262 # include <sys/un.h>
263 # include <netinet/tcp.h>
264 # include <machine/endian.h>
265 # include <sys/time.h>
266 # define IOCHANNEL_TRANSFER_BSD_RENO
267 # define NO_PTHREAD_RTL
268 #endif
270 #if !defined(_WIN32) && \
271 !defined(LINUX) && !defined(NETBSD) && !defined(FREEBSD) && \
272 !defined(AIX) && \
273 !defined(__sun) && !defined(MACOSX) && \
274 !defined(OPENBSD) && !defined(DRAGONFLY) && \
275 !defined(IOS) && !defined(ANDROID) && \
276 !defined(HAIKU)
277 # error "Target platform not specified!"
278 #endif
280 #ifndef PTR_FD_SET
281 # define PTR_FD_SET(s) (&(s))
282 #endif
284 #ifndef NORMALIZE_TIMESPEC
285 # define NORMALIZE_TIMESPEC(timespec) \
286 timespec . tv_sec += timespec . tv_nsec / 1000000000; \
287 timespec . tv_nsec %= 1000000000;
288 #endif
290 #ifndef SET_TIMESPEC
291 # define SET_TIMESPEC(timespec, sec, nsec) \
292 timespec . tv_sec = (sec); \
293 timespec . tv_nsec = (nsec); \
294 NORMALIZE_TIMESPEC(timespec);
295 #endif
297 #ifndef SLEEP_TIMESPEC
298 # define SLEEP_TIMESPEC(timespec) nanosleep(&timespec, nullptr)
299 #endif
301 #ifndef INIT_GROUPS
302 # define INIT_GROUPS(name, gid) ((setgid((gid)) == 0) && (initgroups((name), (gid)) == 0))
303 #endif
305 #ifndef PTHREAD_NONE
306 # define PTHREAD_NONE _pthread_none_
307 # ifndef PTHREAD_NONE_INIT
308 # define PTHREAD_NONE_INIT ((pthread_t)-1)
309 # endif
310 #endif
312 #ifndef PTHREAD_ATTR_DEFAULT
313 # define PTHREAD_ATTR_DEFAULT nullptr
314 #endif
315 #ifndef PTHREAD_MUTEXATTR_DEFAULT
316 # define PTHREAD_MUTEXATTR_DEFAULT nullptr
317 #endif
318 #ifndef PTHREAD_CONDATTR_DEFAULT
319 # define PTHREAD_CONDATTR_DEFAULT nullptr
320 #endif
322 #ifndef PTHREAD_SIGACTION
323 # define PTHREAD_SIGACTION sigaction
324 #endif
326 #ifndef STAT_PARENT
327 # define STAT_PARENT lstat
328 #endif
330 /* socket options which might not be defined on all unx flavors */
331 #ifndef SO_ACCEPTCONN
332 # define SO_ACCEPTCONN 0
333 #endif
334 #ifndef SO_SNDLOWAT
335 # define SO_SNDLOWAT 0
336 #endif
337 #ifndef SO_RCVLOWAT
338 # define SO_RCVLOWAT 0
339 #endif
340 #ifndef SO_SNDTIMEO
341 # define SO_SNDTIMEO 0
342 #endif
343 #ifndef SO_RCVTIMEO
344 # define SO_RCVTIMEO 0
345 #endif
346 #ifndef SO_USELOOPBACK
347 # define SO_USELOOPBACK 0
348 #endif
349 #ifndef MSG_MAXIOVLEN
350 # define MSG_MAXIOVLEN 0
351 #endif
353 /* BEGIN HACK */
354 /* dummy define and declarations for IPX should be replaced by */
355 /* original ipx headers when these are available for this platform */
357 #ifndef SA_FAMILY_DECL
358 # define SA_FAMILY_DECL short sa_family
359 #endif
361 #define NSPROTO_IPX 1000
362 #define NSPROTO_SPX 1256
363 #define NSPROTO_SPXII 1257
365 /* END HACK */
367 #ifdef NO_PTHREAD_RTL
368 #if !defined FREEBSD
369 #if !defined NETBSD
370 struct passwd *getpwent_r(struct passwd *pwd, char *buffer, int buflen);
371 #endif
372 extern struct spwd *getspnam_r(const char *name, struct spwd *result,
373 char *buffer, int buflen);
375 #if !defined MACOSX
376 struct tm *localtime_r(const time_t *timep, struct tm *buffer);
377 struct tm *gmtime_r(const time_t *timep, struct tm *buffer);
378 #endif
379 struct hostent *gethostbyname_r(const char *name, struct hostent *result,
380 char *buffer, size_t buflen, int *h_errnop);
381 #endif /* !defined(FREEBSD) */
382 #endif
384 #endif // INCLUDED_SAL_OSL_UNX_SYSTEM_H
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */