merge the formfield patch from ooo-build
[ooovba.git] / sal / osl / unx / system.h
blob8eaaa7beea6688e6933924436c5b538effcd8430
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: system.h,v $
10 * $Revision: 1.42.60.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __OSL_SYSTEM_H__
32 #define __OSL_SYSTEM_H__
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <limits.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <stdarg.h>
41 #include <unistd.h>
42 #include <fcntl.h>
43 #include <dirent.h>
44 #include <signal.h>
45 #include <utime.h>
47 #include <pwd.h>
49 #include <netdb.h>
51 #include <sys/stat.h>
52 #include <sys/wait.h>
54 #include <sys/types.h>
56 /* Make sockets of type AF_UNIX use underlying FS rights */
57 #ifdef SOLARIS
58 # define _XOPEN_SOURCE 500
59 # include <sys/socket.h>
60 # undef _XOPEN_SOURCE
61 #else
62 # include <sys/socket.h>
63 #endif
65 #include <netinet/in.h>
66 #include <arpa/inet.h>
68 #ifdef SYSV
69 # include <sys/utsname.h>
70 #endif
72 #ifdef LINUX
73 # ifndef __USE_GNU
74 # define __USE_GNU
75 # endif
77 #if GLIBC >= 2
78 # include <shadow.h>
79 # include <pthread.h>
80 # include <sys/file.h>
81 # include <sys/ioctl.h>
82 # include <sys/uio.h>
83 # include <sys/un.h>
84 # include <netinet/tcp.h>
85 # include <dlfcn.h>
86 # include <endian.h>
87 # include <sys/time.h>
88 # include <semaphore.h>
89 # if __BYTE_ORDER == __LITTLE_ENDIAN
90 # define _LITTLE_ENDIAN
91 # elif __BYTE_ORDER == __BIG_ENDIAN
92 # ifndef _BIG_ENDIAN
93 # define _BIG_ENDIAN
94 # endif
95 # elif __BYTE_ORDER == __PDP_ENDIAN
96 # define _PDP_ENDIAN
97 # endif
98 # define IORESOURCE_TRANSFER_BSD
99 # define IOCHANNEL_TRANSFER_BSD_RENO
100 # define pthread_testcancel()
101 # define NO_PTHREAD_PRIORITY
102 # define PTHREAD_SIGACTION pthread_sigaction
103 #else
104 # include <shadow.h>
105 # include <asm/sigcontext.h>
106 # include <pthread.h>
107 # include <sys/file.h>
108 # include <sys/ioctl.h>
109 # include <linux/net.h>
110 # include <sys/un.h>
111 # include <netinet/tcp.h>
112 # include <linux/elfcore.h>
113 # include <dlfcn.h>
114 # include <endian.h>
115 # if __BYTE_ORDER == __LITTLE_ENDIAN
116 # define _LITTLE_ENDIAN
117 # elif __BYTE_ORDER == __BIG_ENDIAN
118 # define _BIG_ENDIAN
119 # elif __BYTE_ORDER == __PDP_ENDIAN
120 # define _PDP_ENDIAN
121 # endif
122 # define IORESOURCE_TRANSFER_BSD
123 # define IOCHANNEL_TRANSFER_BSD_RENO
124 # define pthread_testcancel()
125 # define NO_PTHREAD_RTL
126 # define NO_PTHREAD_PRIORITY
127 # define PTHREAD_SIGACTION pthread_sigaction
128 #endif
129 #endif
131 #ifdef NETBSD
132 # define ETIME ETIMEDOUT
133 # define _POSIX_THREAD_SYSCALL_SOFT 1
134 # include <pthread.h>
135 # include <netdb.h>
136 # include <sys/sem.h>
137 # include <sys/exec.h>
138 # include <sys/filio.h>
139 # include <sys/ioctl.h>
140 # include <sys/time.h>
141 # include <sys/un.h>
142 # include <netinet/tcp.h>
143 # include <dlfcn.h>
144 # include <machine/endian.h>
145 # if BYTE_ORDER == LITTLE_ENDIAN
146 # define _LITTLE_ENDIAN_OO
147 # elif BYTE_ORDER == BIG_ENDIAN
148 # define _BIG_ENDIAN_OO
149 # elif BYTE_ORDER == PDP_ENDIAN
150 # define _PDP_ENDIAN_OO
151 # endif
152 # define IORESOURCE_TRANSFER_BSD
153 # define IOCHANNEL_TRANSFER_BSD_RENO
154 # define pthread_testcancel()
155 # define NO_PTHREAD_PRIORITY
156 # define NO_PTHREAD_SEMAPHORES
157 # define NO_PTHREAD_RTL
158 # define PTHREAD_SIGACTION pthread_sigaction
159 #endif
161 #ifdef FREEBSD
162 # define ETIME ETIMEDOUT
163 # include <pthread.h>
164 # include <sys/sem.h>
165 # include <semaphore.h>
166 # include <dlfcn.h>
167 # include <sys/filio.h>
168 # include <sys/ioctl.h>
169 # include <sys/param.h>
170 # include <sys/time.h>
171 # include <sys/uio.h>
172 # include <sys/exec.h>
173 # include <vm/vm.h>
174 # include <vm/vm_param.h>
175 # include <vm/pmap.h>
176 # include <vm/swap_pager.h>
177 # include <sys/un.h>
178 # include <netinet/tcp.h>
179 # define IORESOURCE_TRANSFER_BSD
180 # include <machine/endian.h>
181 #if __FreeBSD_version < 500000
182 # if BYTE_ORDER == LITTLE_ENDIAN
183 # define _LITTLE_ENDIAN
184 # elif BYTE_ORDER == BIG_ENDIAN
185 # define _BIG_ENDIAN
186 # elif BYTE_ORDER == PDP_ENDIAN
187 # define _PDP_ENDIAN
188 # endif
189 #endif
190 # define NO_PTHREAD_RTL
191 #endif
193 #ifdef SCO
194 # define AF_IPX -1
195 # include <strings.h>
196 # include <pthread.h>
197 # include <shadow.h>
198 # include <netdb.h>
199 # include <sys/un.h>
200 # include <sys/netinet/tcp.h>
201 # include <sys/types.h>
202 # include <sys/byteorder.h>
203 # include <dlfcn.h>
204 # if BYTE_ORDER == LITTLE_ENDIAN
205 # define _LITTLE_ENDIAN
206 # elif BYTE_ORDER == BIG_ENDIAN
207 # define _BIG_ENDIAN
208 # elif BYTE_ORDER == PDP_ENDIAN
209 # define _PDP_ENDIAN
210 # endif
211 # define sched_yield() pthread_yield()
212 # define pthread_testcancel()
213 # define NO_PTHREAD_RTL
214 # define NO_PTHREAD_PRIORITY
215 extern int pthread_cancel(pthread_t);
216 extern unsigned int nanosleep(unsigned int);
217 # define SLEEP_TIMESPEC(timespec) (timespec .tv_sec > 0) ? sleep(timespec .tv_sec), nanosleep(timespec .tv_nsec) : nanosleep(timespec .tv_nsec)
218 # define PATH_MAX _POSIX_PATH_MAX
219 # define S_ISSOCK S_ISFIFO
220 # define PTHREAD_SIGACTION pthread_sigaction
221 # define STAT_PARENT stat
222 #endif
224 #ifdef AIX
225 # define AF_IPX -1
226 # include <strings.h>
227 # include <pthread.h>
228 # include <sys/time.h>
229 # include <sys/un.h>
230 # include <netinet/tcp.h>
231 # include <sys/machine.h>
232 # if BYTE_ORDER == LITTLE_ENDIAN
233 # define _LITTLE_ENDIAN
234 # elif BYTE_ORDER == BIG_ENDIAN
235 # define _BIG_ENDIAN
236 # elif BYTE_ORDER == PDP_ENDIAN
237 # define _PDP_ENDIAN
238 # endif
239 # define sched_yield() pthread_yield()
240 # define SLEEP_TIMESPEC(timespec) nsleep(&timespec, 0)
241 # define LIBPATH "LIBPATH"
242 # define NO_PTHREAD_SEMAPHORES
243 # define NO_DL_FUNCTIONS
244 #endif
246 #ifdef HPUX
247 # define AF_IPX -1
248 # undef howmany
249 # undef MAXINT
250 # include <pthread.h>
251 # include <sys/un.h>
252 # include <sys/sched.h>
253 # include <sys/xti.h>
254 # include <sys/pstat.h>
255 # include <shadow.h>
256 # include <crypt.h>
257 # include <machine/param.h>
258 # define LIBPATH "SHLIB_PATH"
259 # define PTR_FD_SET(s) ((int *)&(s))
260 # define PTHREAD_VALUE(t) ((t).field2)
261 # define PTHREAD_NONE_INIT { 0, -1 }
262 # define PTHREAD_ATTR_DEFAULT pthread_attr_default
263 # define PTHREAD_MUTEXATTR_DEFAULT pthread_mutexattr_default
264 # define PTHREAD_CONDATTR_DEFAULT pthread_condattr_default
265 # define pthread_detach(t) pthread_detach(&(t))
266 # define NO_PTHREAD_PRIORITY
267 # define NO_PTHREAD_SEMAPHORES
268 # define NO_DL_FUNCTIONS
269 # undef sigaction
270 # define PTHREAD_SIGACTION cma_sigaction
271 #endif
273 #ifdef IRIX
274 # define AF_IPX -1
275 # include <pthread.h>
276 # include <semaphore.h>
277 # include <sched.h>
278 # include <sys/socket.h>
279 # include <sys/un.h>
280 # include <sys/stropts.h>
281 # include <netinet/tcp.h>
282 # include <sys/endian.h>
283 # if BYTE_ORDER == LITTLE_ENDIAN
284 # undef _BIG_ENDIAN
285 # undef _PDP_ENDIAN
286 # elif BYTE_ORDER == BIG_ENDIAN
287 # undef _LITTLE_ENDIAN
288 # undef _PDP_ENDIAN
289 # elif BYTE_ORDER == PDP_ENDIAN
290 # undef _LITTLE_ENDIAN
291 # undef _BIG_ENDIAN
292 # endif
293 # define SA_FAMILY_DECL \
294 union { struct { short sa_family2; } sa_generic; } sa_union
295 # define NO_PTHREAD_PRIORITY
296 # include <dlfcn.h>
297 # define IOCHANNEL_TRANSFER_BSD
298 extern char *strdup(const char *);
299 #endif
301 #ifdef SOLARIS
302 # include <shadow.h>
303 # include <sys/un.h>
304 # include <stropts.h>
305 # include <pthread.h>
306 # include <semaphore.h>
307 # include <netinet/tcp.h>
308 # include <sys/filio.h>
309 # include <dlfcn.h>
310 # include <sys/isa_defs.h>
311 # define IORESOURCE_TRANSFER_SYSV
312 # define IOCHANNEL_TRANSFER_BSD
313 # define LIBPATH "LD_LIBRARY_PATH"
314 #endif
316 #ifdef MACOSX
317 #define __OPENTRANSPORTPROVIDERS__ // these are already defined
318 #define TimeValue CFTimeValue // Do not conflict with TimeValue in sal/inc/osl/time.h
319 #include <Carbon/Carbon.h>
320 #undef TimeValue
321 # ifndef ETIME
322 # define ETIME ETIMEDOUT
323 # endif
324 # include <dlfcn.h>
325 # include <pthread.h>
326 # include <sys/file.h>
327 # include <sys/ioctl.h>
328 # include <sys/uio.h>
329 # include <sys/un.h>
330 # include <netinet/tcp.h>
331 # include <machine/endian.h>
332 # include <sys/time.h>
333 # include <sys/semaphore.h>
334 /* fixme are premac and postmac still needed here? */
335 # include <premac.h>
336 # include <mach-o/dyld.h>
337 # include <postmac.h>
338 # if BYTE_ORDER == LITTLE_ENDIAN
339 # ifndef _LITTLE_ENDIAN
340 # define _LITTLE_ENDIAN
341 # endif
342 # elif BYTE_ORDER == BIG_ENDIAN
343 # ifndef _BIG_ENDIAN
344 # define _BIG_ENDIAN
345 # endif
346 # elif BYTE_ORDER == PDP_ENDIAN
347 # ifndef _PDP_ENDIAN
348 # define _PDP_ENDIAN
349 # endif
350 # endif
351 # define IOCHANNEL_TRANSFER_BSD_RENO
352 # define NO_PTHREAD_RTL
353 /* for NSGetArgc/Argv/Environ */
354 # include <crt_externs.h>
355 #ifdef __cplusplus
356 extern "C" {
357 #endif
358 int macxp_resolveAlias(char *path, int buflen);
359 #ifdef __cplusplus
361 #endif
362 #endif
364 #if !defined(_WIN32) && !defined(_WIN16) && !defined(OS2) && \
365 !defined(LINUX) && !defined(NETBSD) && !defined(FREEBSD) && !defined(SCO) && \
366 !defined(AIX) && !defined(HPUX) && \
367 !defined(SOLARIS) && !defined(IRIX) && \
368 !defined(MACOSX)
369 # error "Target platform not specified!"
370 #endif
372 #if defined(NETBSD)
373 #if defined _LITTLE_ENDIAN_OO
374 # define _OSL_BIGENDIAN
375 #elif defined _BIG_ENDIAN_OO
376 # define _OSL_LITENDIAN
377 #else
378 # error undetermined endianess
379 #endif
380 #else
381 #if defined _LITTLE_ENDIAN
382 # define _OSL_BIGENDIAN
383 #elif defined _BIG_ENDIAN
384 # define _OSL_LITENDIAN
385 #else
386 # error undetermined endianess
387 #endif
388 #endif
390 #ifndef PTR_FD_SET
391 # define PTR_FD_SET(s) (&(s))
392 #endif
394 #ifndef NORMALIZE_TIMESPEC
395 # define NORMALIZE_TIMESPEC(timespec) \
396 timespec . tv_sec += timespec . tv_nsec / 1000000000; \
397 timespec . tv_nsec %= 1000000000;
398 #endif
400 #ifndef SET_TIMESPEC
401 # define SET_TIMESPEC(timespec, sec, nsec) \
402 timespec . tv_sec = (sec); \
403 timespec . tv_nsec = (nsec); \
404 NORMALIZE_TIMESPEC(timespec);
405 #endif
407 #ifndef SLEEP_TIMESPEC
408 # define SLEEP_TIMESPEC(timespec) nanosleep(&timespec, 0)
409 #endif
411 #ifndef INIT_GROUPS
412 # define INIT_GROUPS(name, gid) ((setgid((gid)) == 0) && (initgroups((name), (gid)) == 0))
413 #endif
415 #ifndef PTHREAD_VALUE
416 # define PTHREAD_VALUE(t) (t)
417 #endif
418 #ifndef PTHREAD_NONE
419 # if (__GNUC__ < 4) && !defined(MACOSX)
420 extern pthread_t _pthread_none_;
421 # endif
422 # define PTHREAD_NONE _pthread_none_
423 # ifndef PTHREAD_NONE_INIT
424 # define PTHREAD_NONE_INIT ((pthread_t)-1)
425 # endif
426 #endif
428 #ifndef PTHREAD_ATTR_DEFAULT
429 # define PTHREAD_ATTR_DEFAULT NULL
430 #endif
431 #ifndef PTHREAD_MUTEXATTR_DEFAULT
432 # define PTHREAD_MUTEXATTR_DEFAULT NULL
433 #endif
434 #ifndef PTHREAD_CONDATTR_DEFAULT
435 # define PTHREAD_CONDATTR_DEFAULT NULL
436 #endif
438 #ifndef PTHREAD_SIGACTION
439 # define PTHREAD_SIGACTION sigaction
440 #endif
442 #ifndef STAT_PARENT
443 # define STAT_PARENT lstat
444 #endif
446 /* socket options which might not be defined on all unx flavors */
447 #ifndef SO_ACCEPTCONN
448 # define SO_ACCEPTCONN 0
449 #endif
450 #ifndef SO_SNDLOWAT
451 # define SO_SNDLOWAT 0
452 #endif
453 #ifndef SO_RCVLOWAT
454 # define SO_RCVLOWAT 0
455 #endif
456 #ifndef SO_SNDTIMEO
457 # define SO_SNDTIMEO 0
458 #endif
459 #ifndef SO_RCVTIMEO
460 # define SO_RCVTIMEO 0
461 #endif
462 #ifndef SO_USELOOPBACK
463 # define SO_USELOOPBACK 0
464 #endif
465 #ifndef MSG_MAXIOVLEN
466 # define MSG_MAXIOVLEN 0
467 #endif
469 /* BEGIN HACK */
470 /* dummy define and declarations for IPX should be replaced by */
471 /* original ipx headers when these are available for this platform */
473 #ifndef SA_FAMILY_DECL
474 # define SA_FAMILY_DECL short sa_family
475 #endif
477 typedef struct sockaddr_ipx {
478 SA_FAMILY_DECL;
479 char sa_netnum[4];
480 char sa_nodenum[6];
481 unsigned short sa_socket;
482 } SOCKADDR_IPX;
484 #define NSPROTO_IPX 1000
485 #define NSPROTO_SPX 1256
486 #define NSPROTO_SPXII 1257
488 /* END HACK */
490 #ifdef NO_PTHREAD_SEMAPHORES
492 typedef struct
494 pthread_mutex_t mutex;
495 pthread_cond_t increased;
496 int value;
497 } sem_t;
498 extern int sem_init(sem_t* sem, int pshared, unsigned int value);
499 extern int sem_destroy(sem_t* sem);
500 extern int sem_wait(sem_t* sem);
501 extern int sem_trywait(sem_t* sem);
502 extern int sem_post(sem_t* sem);
504 #endif
506 #ifdef NO_PTHREAD_RTL
507 #if !defined FREEBSD || (__FreeBSD_version < 500112)
508 struct passwd *getpwent_r(struct passwd *pwd, char *buffer, int buflen);
509 extern struct spwd *getspnam_r(const char *name, struct spwd *result,
510 char *buffer, int buflen);
512 struct tm *localtime_r(const time_t *timep, struct tm *buffer);
513 struct tm *gmtime_r(const time_t *timep, struct tm *buffer);
514 #endif /* !defined FREEBSD || (__FreeBSD_version < 500112) */
515 #if !defined(FREEBSD) || (__FreeBSD_version < 601103)
516 struct hostent *gethostbyname_r(const char *name, struct hostent *result,
517 char *buffer, int buflen, int *h_errnop);
518 #endif /* !defined(FREEBSD) || (__FreeBSD_version < 601103) */
519 #endif
521 #endif /* __OSL_SYSTEM_H__ */