Update ooo320-m1
[ooovba.git] / sal / osl / os2 / system.h
blobe693bf8304eac371980ca329410e5c07766364fb
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.5.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 #define PTHREAD_NONE
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <limits.h>
39 #include <string.h>
40 #include <errno.h>
41 #include <stdarg.h>
43 #include <unistd.h>
44 #include <fcntl.h>
45 #include <dirent.h>
46 #include <signal.h>
47 #include <utime.h>
49 #include <pwd.h>
51 #include <netdb.h>
53 #include <sys/stat.h>
54 #include <sys/wait.h>
56 #include <sys/types.h>
58 /* OS/2 API header */
59 #define INCL_WINPROGRAMLIST
60 #define INCL_WINSHELLDATA
61 #define INCL_BASE
62 #define INCL_DOSSIGNALS
63 #define INCL_DOSSEMAPHORES
64 #define INCL_DOSMODULEMGR
65 #define INCL_DOSERRORS
66 #define INCL_DOSSESMGR
67 #define INCL_DOSPROCESS
68 #define INCL_DOSNMPIPES
69 #define INCL_DOSMISC
70 #include <os2.h>
72 typedef ULONG HANDLE;
73 #define _MAX_ENV 2048
74 #define _MAX_CMD 2048
76 #ifdef __cplusplus
77 extern "C"
78 #endif
79 int debug_printf(const char *f, ...);
81 /* Make sockets of type AF_UNIX use underlying FS rights */
82 #ifdef SOLARIS
83 # define _XOPEN_SOURCE 500
84 # include <sys/socket.h>
85 # undef _XOPEN_SOURCE
86 #else
87 # include <sys/socket.h>
88 #endif
90 #include <netinet/in.h>
91 #include <arpa/inet.h>
93 #define max(a, b) ((a) < (b) ? (b) : (a))
94 #define min(a, b) ((a) > (b) ? (b) : (a))
95 #ifndef abs
96 #define abs(x) ((x) >= 0 ? (x) : -(x))
97 #endif
99 #ifdef SYSV
100 # include <sys/utsname.h>
101 #endif
103 #ifdef LINUX
104 # ifndef __USE_GNU
105 # define __USE_GNU
106 # endif
108 #if GLIBC >= 2
109 # include <shadow.h>
110 # if ! (defined(SPARC) || defined(X86_64))
111 # include <asm/sigcontext.h>
112 # endif
113 # include <pthread.h>
114 # include <sys/file.h>
115 # include <sys/ioctl.h>
116 # include <sys/uio.h>
117 # include <sys/un.h>
118 # include <netinet/tcp.h>
119 # include <dlfcn.h>
120 # include <endian.h>
121 # include <sys/time.h>
122 # include <semaphore.h>
123 # if __BYTE_ORDER == __LITTLE_ENDIAN
124 # define _LITTLE_ENDIAN
125 # elif __BYTE_ORDER == __BIG_ENDIAN
126 # define _BIG_ENDIAN
127 # elif __BYTE_ORDER == __PDP_ENDIAN
128 # define _PDP_ENDIAN
129 # endif
130 # define PTR_SIZE_T(s) ((size_t *)&(s))
131 # define IORESOURCE_TRANSFER_BSD
132 # define IOCHANNEL_TRANSFER_BSD_RENO
133 # define pthread_testcancel()
134 # define NO_PTHREAD_PRIORITY
135 # define PTHREAD_SIGACTION pthread_sigaction
136 #else
137 # include <shadow.h>
138 # include <asm/sigcontext.h>
139 # include <pthread.h>
140 # include <sys/file.h>
141 # include <sys/ioctl.h>
142 # include <linux/net.h>
143 # include <sys/un.h>
144 # include <netinet/tcp.h>
145 # include <linux/elfcore.h>
146 # include <dlfcn.h>
147 # include <endian.h>
148 # if __BYTE_ORDER == __LITTLE_ENDIAN
149 # define _LITTLE_ENDIAN
150 # elif __BYTE_ORDER == __BIG_ENDIAN
151 # define _BIG_ENDIAN
152 # elif __BYTE_ORDER == __PDP_ENDIAN
153 # define _PDP_ENDIAN
154 # endif
155 # define IORESOURCE_TRANSFER_BSD
156 # define IOCHANNEL_TRANSFER_BSD_RENO
157 # define pthread_testcancel()
158 # define NO_PTHREAD_RTL
159 # define NO_PTHREAD_PRIORITY
160 # define PTHREAD_SIGACTION pthread_sigaction
161 #endif
162 #endif
164 #ifdef NETBSD
165 # define ETIME ETIMEDOUT
166 # define _POSIX_THREAD_SYSCALL_SOFT 1
167 # include <pthread.h>
168 # include <netdb.h>
169 # include <sys/sem.h>
170 # include <sys/exec.h>
171 # include <sys/filio.h>
172 # include <sys/ioctl.h>
173 # include <sys/time.h>
174 # include <sys/un.h>
175 # include <netinet/tcp.h>
176 # include <dlfcn.h>
177 # include <machine/endian.h>
178 # if BYTE_ORDER == LITTLE_ENDIAN
179 # define _LITTLE_ENDIAN_OO
180 # elif BYTE_ORDER == BIG_ENDIAN
181 # define _BIG_ENDIAN_OO
182 # elif BYTE_ORDER == PDP_ENDIAN
183 # define _PDP_ENDIAN_OO
184 # endif
185 # define PTR_SIZE_T(s) ((size_t *)&(s))
186 # define IORESOURCE_TRANSFER_BSD
187 # define IOCHANNEL_TRANSFER_BSD_RENO
188 # define pthread_testcancel()
189 # define NO_PTHREAD_PRIORITY
190 # define NO_PTHREAD_SEMAPHORES
191 # define NO_PTHREAD_RTL
192 # define PTHREAD_SIGACTION pthread_sigaction
193 #endif
195 #ifdef FREEBSD
196 # define ETIME ETIMEDOUT
197 # include <pthread.h>
198 # include <sys/sem.h>
199 # include <semaphore.h>
200 # include <dlfcn.h>
201 # include <sys/filio.h>
202 # include <sys/ioctl.h>
203 # include <sys/param.h>
204 # include <sys/time.h>
205 # include <sys/uio.h>
206 # include <sys/exec.h>
207 # include <vm/vm.h>
208 # include <vm/vm_param.h>
209 # include <vm/pmap.h>
210 # include <vm/swap_pager.h>
211 # include <sys/un.h>
212 # include <netinet/tcp.h>
213 # define IORESOURCE_TRANSFER_BSD
214 # include <machine/endian.h>
215 #if __FreeBSD_version < 500000
216 # if BYTE_ORDER == LITTLE_ENDIAN
217 # define _LITTLE_ENDIAN
218 # elif BYTE_ORDER == BIG_ENDIAN
219 # define _BIG_ENDIAN
220 # elif BYTE_ORDER == PDP_ENDIAN
221 # define _PDP_ENDIAN
222 # endif
223 #endif
224 # define NO_PTHREAD_RTL
225 #endif
227 #ifdef SCO
228 # define AF_IPX -1
229 # include <strings.h>
230 # include <pthread.h>
231 # include <shadow.h>
232 # include <netdb.h>
233 # include <sys/un.h>
234 # include <sys/netinet/tcp.h>
235 # include <sys/types.h>
236 # include <sys/byteorder.h>
237 # include <dlfcn.h>
238 # if BYTE_ORDER == LITTLE_ENDIAN
239 # define _LITTLE_ENDIAN
240 # elif BYTE_ORDER == BIG_ENDIAN
241 # define _BIG_ENDIAN
242 # elif BYTE_ORDER == PDP_ENDIAN
243 # define _PDP_ENDIAN
244 # endif
245 # define sched_yield() pthread_yield()
246 # define pthread_testcancel()
247 # define NO_PTHREAD_RTL
248 # define NO_PTHREAD_PRIORITY
249 extern int pthread_cancel(pthread_t);
250 extern unsigned int nanosleep(unsigned int);
251 # define SLEEP_TIMESPEC(timespec) (timespec .tv_sec > 0) ? sleep(timespec .tv_sec), nanosleep(timespec .tv_nsec) : nanosleep(timespec .tv_nsec)
252 # define PATH_MAX _POSIX_PATH_MAX
253 # define S_ISSOCK S_ISFIFO
254 # define PTHREAD_SIGACTION pthread_sigaction
255 # define STAT_PARENT stat
256 #endif
258 #ifdef AIX
259 # define AF_IPX -1
260 # include <strings.h>
261 # include <pthread.h>
262 # include <sys/time.h>
263 # include <sys/un.h>
264 # include <netinet/tcp.h>
265 # include <sys/machine.h>
266 # if BYTE_ORDER == LITTLE_ENDIAN
267 # define _LITTLE_ENDIAN
268 # elif BYTE_ORDER == BIG_ENDIAN
269 # define _BIG_ENDIAN
270 # elif BYTE_ORDER == PDP_ENDIAN
271 # define _PDP_ENDIAN
272 # endif
273 # define sched_yield() pthread_yield()
274 # define SLEEP_TIMESPEC(timespec) nsleep(&timespec, 0)
275 # define LIBPATH "LIBPATH"
276 # define PTR_SIZE_T(s) ((size_t *)&(s))
277 # define NO_PTHREAD_SEMAPHORES
278 # define NO_DL_FUNCTIONS
279 #endif
281 #ifdef HPUX
282 # define AF_IPX -1
283 # undef howmany
284 # undef MAXINT
285 # include <pthread.h>
286 # include <sys/un.h>
287 # include <sys/sched.h>
288 # include <sys/xti.h>
289 # include <sys/pstat.h>
290 # include <shadow.h>
291 # include <crypt.h>
292 # include <machine/param.h>
293 # define LIBPATH "SHLIB_PATH"
294 # define PTR_SIZE_T(s) ((int *)&(s))
295 # define PTR_FD_SET(s) ((int *)&(s))
296 # define PTHREAD_VALUE(t) ((t).field2)
297 # define PTHREAD_NONE_INIT { 0, -1 }
298 # define PTHREAD_ATTR_DEFAULT pthread_attr_default
299 # define PTHREAD_MUTEXATTR_DEFAULT pthread_mutexattr_default
300 # define PTHREAD_CONDATTR_DEFAULT pthread_condattr_default
301 # define pthread_detach(t) pthread_detach(&(t))
302 # define NO_PTHREAD_PRIORITY
303 # define NO_PTHREAD_SEMAPHORES
304 # define NO_DL_FUNCTIONS
305 # undef sigaction
306 # define PTHREAD_SIGACTION cma_sigaction
307 #endif
309 #ifdef IRIX
310 # define AF_IPX -1
311 # include <pthread.h>
312 # include <semaphore.h>
313 # include <sched.h>
314 # include <sys/socket.h>
315 # include <sys/un.h>
316 # include <sys/stropts.h>
317 # include <netinet/tcp.h>
318 # include <procfs/procfs.h>
319 # include <sys/endian.h>
320 # if BYTE_ORDER == LITTLE_ENDIAN
321 # undef _BIG_ENDIAN
322 # undef _PDP_ENDIAN
323 # elif BYTE_ORDER == BIG_ENDIAN
324 # undef _LITTLE_ENDIAN
325 # undef _PDP_ENDIAN
326 # elif BYTE_ORDER == PDP_ENDIAN
327 # undef _LITTLE_ENDIAN
328 # undef _BIG_ENDIAN
329 # endif
330 # define SA_FAMILY_DECL \
331 union { struct { short sa_family2; } sa_generic; } sa_union
332 # define PTR_SIZE_T(s) ((int *)&(s))
333 # define NO_PTHREAD_PRIORITY
334 # include <dlfcn.h>
335 # define IOCHANNEL_TRANSFER_BSD
336 extern char *strdup(const char *);
337 #endif
339 #ifdef SOLARIS
340 # include <shadow.h>
341 # include <sys/procfs.h>
342 # include <sys/un.h>
343 # include <stropts.h>
344 # include <pthread.h>
345 # include <semaphore.h>
346 # include <netinet/tcp.h>
347 # include <sys/filio.h>
348 # include <dlfcn.h>
349 # include <sys/isa_defs.h>
350 # define IORESOURCE_TRANSFER_SYSV
351 # define IOCHANNEL_TRANSFER_BSD
352 # define LIBPATH "LD_LIBRARY_PATH"
353 # define PTR_SIZE_T(s) ((int *)&(s))
354 #endif
356 #ifdef MACOSX
357 # define ETIME ETIMEDOUT
358 # include <pthread.h>
359 # include <sys/file.h>
360 # include <sys/ioctl.h>
361 # include <sys/uio.h>
362 # include <sys/un.h>
363 # include <netinet/tcp.h>
364 # include <machine/endian.h>
365 # include <sys/time.h>
366 # include <sys/semaphore.h>
367 /* fixme are premac and postmac still needed here? */
368 # include <premac.h>
369 # include <mach-o/dyld.h>
370 # include <postmac.h>
371 # if BYTE_ORDER == LITTLE_ENDIAN
372 # define _LITTLE_ENDIAN
373 # elif BYTE_ORDER == BIG_ENDIAN
374 # define _BIG_ENDIAN
375 # elif BYTE_ORDER == PDP_ENDIAN
376 # define _PDP_ENDIAN
377 # endif
378 # define IOCHANNEL_TRANSFER_BSD_RENO
379 # define NO_PTHREAD_RTL
380 /* for NSGetArgc/Argv/Environ */
381 # include <crt_externs.h>
382 char *macxp_tempnam( const char *tmpdir, const char *prefix );
383 #endif
385 #ifdef OS2
386 # include <netinet/tcp.h>
387 #endif
389 #if !defined(_WIN32) && !defined(_WIN16) && !defined(OS2) && \
390 !defined(LINUX) && !defined(NETBSD) && !defined(FREEBSD) && !defined(SCO) && \
391 !defined(AIX) && !defined(HPUX) && \
392 !defined(SOLARIS) && !defined(IRIX) && !defined(MAC) && \
393 !defined(MACOSX)
394 # error "Target plattform not specified !"
395 #endif
397 #if defined(NETBSD)
398 #if defined _LITTLE_ENDIAN_OO
399 # define _OSL_BIGENDIAN
400 #elif defined _BIG_ENDIAN_OO
401 # define _OSL_LITENDIAN
402 #else
403 # error undetermined endianess
404 #endif
405 #else
406 #if defined _LITTLE_ENDIAN
407 # define _OSL_BIGENDIAN
408 #elif defined _BIG_ENDIAN
409 # define _OSL_LITENDIAN
410 #else
411 # error undetermined endianess
412 #endif
413 #endif
415 #ifndef PTR_SIZE_T
416 # define PTR_SIZE_T(s) (&(s))
417 #endif
419 #ifndef PTR_FD_SET
420 # define PTR_FD_SET(s) (&(s))
421 #endif
423 #ifndef NORMALIZE_TIMESPEC
424 # define NORMALIZE_TIMESPEC(timespec) \
425 timespec . tv_sec += timespec . tv_nsec / 1000000000; \
426 timespec . tv_nsec %= 1000000000;
427 #endif
429 #ifndef SET_TIMESPEC
430 # define SET_TIMESPEC(timespec, sec, nsec) \
431 timespec . tv_sec = (sec); \
432 timespec . tv_nsec = (nsec); \
433 NORMALIZE_TIMESPEC(timespec);
434 #endif
436 #ifndef SLEEP_TIMESPEC
437 # define SLEEP_TIMESPEC(timespec) nanosleep(&timespec, 0)
438 #endif
440 #ifndef INIT_GROUPS
441 # define INIT_GROUPS(name, gid) ((setgid((gid)) == 0) && (initgroups((name), (gid)) == 0))
442 #endif
444 #ifndef PTHREAD_VALUE
445 # define PTHREAD_VALUE(t) (t)
446 #endif
447 #ifndef PTHREAD_NONE
448 extern pthread_t _pthread_none_;
449 # define PTHREAD_NONE _pthread_none_
450 # ifndef PTHREAD_NONE_INIT
451 # define PTHREAD_NONE_INIT ((pthread_t)-1)
452 # endif
453 #endif
455 #ifndef PTHREAD_ATTR_DEFAULT
456 # define PTHREAD_ATTR_DEFAULT NULL
457 #endif
458 #ifndef PTHREAD_MUTEXATTR_DEFAULT
459 # define PTHREAD_MUTEXATTR_DEFAULT NULL
460 #endif
461 #ifndef PTHREAD_CONDATTR_DEFAULT
462 # define PTHREAD_CONDATTR_DEFAULT NULL
463 #endif
465 #ifndef PTHREAD_SIGACTION
466 # define PTHREAD_SIGACTION sigaction
467 #endif
469 #ifndef STAT_PARENT
470 # define STAT_PARENT lstat
471 #endif
473 /* socket options which might not be defined on all unx flavors */
474 #ifndef SO_ACCEPTCONN
475 # define SO_ACCEPTCONN 0
476 #endif
477 #ifndef SO_SNDLOWAT
478 # define SO_SNDLOWAT 0
479 #endif
480 #ifndef SO_RCVLOWAT
481 # define SO_RCVLOWAT 0
482 #endif
483 #ifndef SO_SNDTIMEO
484 # define SO_SNDTIMEO 0
485 #endif
486 #ifndef SO_RCVTIMEO
487 # define SO_RCVTIMEO 0
488 #endif
489 #ifndef SO_USELOOPBACK
490 # define SO_USELOOPBACK 0
491 #endif
492 #ifndef MSG_MAXIOVLEN
493 # define MSG_MAXIOVLEN 0
494 #endif
496 /* BEGIN HACK */
497 /* dummy define and declarations for IPX should be replaced by */
498 /* original ipx headers when these are available for this platform */
500 #ifndef SA_FAMILY_DECL
501 # define SA_FAMILY_DECL short sa_family
502 #endif
504 typedef struct sockaddr_ipx {
505 SA_FAMILY_DECL;
506 char sa_netnum[4];
507 char sa_nodenum[6];
508 unsigned short sa_socket;
509 } SOCKADDR_IPX;
511 #define NSPROTO_IPX 1000
512 #define NSPROTO_SPX 1256
513 #define NSPROTO_SPXII 1257
515 /* END HACK */
517 #ifdef NO_PTHREAD_SEMAPHORES
519 typedef struct
521 pthread_mutex_t mutex;
522 pthread_cond_t increased;
523 int value;
524 } sem_t;
525 extern int sem_init(sem_t* sem, int pshared, unsigned int value);
526 extern int sem_destroy(sem_t* sem);
527 extern int sem_wait(sem_t* sem);
528 extern int sem_trywait(sem_t* sem);
529 extern int sem_post(sem_t* sem);
531 #endif
533 #ifdef NO_PTHREAD_RTL
534 #if !defined FREEBSD || (__FreeBSD_version < 500112)
535 struct passwd *getpwent_r(struct passwd *pwd, char *buffer, int buflen);
536 extern struct spwd *getspnam_r(const char *name, struct spwd *result,
537 char *buffer, int buflen);
539 struct tm *localtime_r(const time_t *timep, struct tm *buffer);
540 struct tm *gmtime_r(const time_t *timep, struct tm *buffer);
541 #endif /* !defined FREEBSD || (__FreeBSD_version < 500112) */
542 struct hostent *gethostbyname_r(const char *name, struct hostent *result,
543 char *buffer, int buflen, int *h_errnop);
544 #endif
546 #endif /* __OSL_SYSTEM_H__ */