1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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__
56 #include <sys/types.h>
59 #define INCL_WINPROGRAMLIST
60 #define INCL_WINSHELLDATA
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
79 int debug_printf(const char *f
, ...);
81 /* Make sockets of type AF_UNIX use underlying FS rights */
83 # define _XOPEN_SOURCE 500
84 # include <sys/socket.h>
87 # include <sys/socket.h>
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))
96 #define abs(x) ((x) >= 0 ? (x) : -(x))
100 # include <sys/utsname.h>
110 # if ! (defined(SPARC) || defined(X86_64))
111 # include <asm/sigcontext.h>
113 # include <pthread.h>
114 # include <sys/file.h>
115 # include <sys/ioctl.h>
116 # include <sys/uio.h>
118 # include <netinet/tcp.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
127 # elif __BYTE_ORDER == __PDP_ENDIAN
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
138 # include <asm/sigcontext.h>
139 # include <pthread.h>
140 # include <sys/file.h>
141 # include <sys/ioctl.h>
142 # include <linux/net.h>
144 # include <netinet/tcp.h>
145 # include <linux/elfcore.h>
148 # if __BYTE_ORDER == __LITTLE_ENDIAN
149 # define _LITTLE_ENDIAN
150 # elif __BYTE_ORDER == __BIG_ENDIAN
152 # elif __BYTE_ORDER == __PDP_ENDIAN
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
165 # define ETIME ETIMEDOUT
166 # define _POSIX_THREAD_SYSCALL_SOFT 1
167 # include <pthread.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>
175 # include <netinet/tcp.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
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
196 # define ETIME ETIMEDOUT
197 # include <pthread.h>
198 # include <sys/sem.h>
199 # include <semaphore.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>
208 # include <vm/vm_param.h>
209 # include <vm/pmap.h>
210 # include <vm/swap_pager.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
220 # elif BYTE_ORDER == PDP_ENDIAN
224 # define NO_PTHREAD_RTL
229 # include <strings.h>
230 # include <pthread.h>
234 # include <sys/netinet/tcp.h>
235 # include <sys/types.h>
236 # include <sys/byteorder.h>
238 # if BYTE_ORDER == LITTLE_ENDIAN
239 # define _LITTLE_ENDIAN
240 # elif BYTE_ORDER == BIG_ENDIAN
242 # elif BYTE_ORDER == PDP_ENDIAN
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
260 # include <strings.h>
261 # include <pthread.h>
262 # include <sys/time.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
270 # elif BYTE_ORDER == PDP_ENDIAN
273 # define sched_yield() pthread_yield()
274 # define SLEEP_TIMESPEC(timespec) nsleep(×pec, 0)
275 # define LIBPATH "LIBPATH"
276 # define PTR_SIZE_T(s) ((size_t *)&(s))
277 # define NO_PTHREAD_SEMAPHORES
278 # define NO_DL_FUNCTIONS
285 # include <pthread.h>
287 # include <sys/sched.h>
288 # include <sys/xti.h>
289 # include <sys/pstat.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
306 # define PTHREAD_SIGACTION cma_sigaction
311 # include <pthread.h>
312 # include <semaphore.h>
314 # include <sys/socket.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
323 # elif BYTE_ORDER == BIG_ENDIAN
324 # undef _LITTLE_ENDIAN
326 # elif BYTE_ORDER == PDP_ENDIAN
327 # undef _LITTLE_ENDIAN
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
335 # define IOCHANNEL_TRANSFER_BSD
336 extern char *strdup(const char *);
341 # include <sys/procfs.h>
343 # include <stropts.h>
344 # include <pthread.h>
345 # include <semaphore.h>
346 # include <netinet/tcp.h>
347 # include <sys/filio.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))
357 # define ETIME ETIMEDOUT
358 # include <pthread.h>
359 # include <sys/file.h>
360 # include <sys/ioctl.h>
361 # include <sys/uio.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? */
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
375 # elif BYTE_ORDER == PDP_ENDIAN
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
);
386 # include <netinet/tcp.h>
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) && \
394 # error "Target plattform not specified !"
398 #if defined _LITTLE_ENDIAN_OO
399 # define _OSL_BIGENDIAN
400 #elif defined _BIG_ENDIAN_OO
401 # define _OSL_LITENDIAN
403 # error undetermined endianess
406 #if defined _LITTLE_ENDIAN
407 # define _OSL_BIGENDIAN
408 #elif defined _BIG_ENDIAN
409 # define _OSL_LITENDIAN
411 # error undetermined endianess
416 # define PTR_SIZE_T(s) (&(s))
420 # define PTR_FD_SET(s) (&(s))
423 #ifndef NORMALIZE_TIMESPEC
424 # define NORMALIZE_TIMESPEC(timespec) \
425 timespec . tv_sec += timespec . tv_nsec / 1000000000; \
426 timespec . tv_nsec %= 1000000000;
430 # define SET_TIMESPEC(timespec, sec, nsec) \
431 timespec . tv_sec = (sec); \
432 timespec . tv_nsec = (nsec); \
433 NORMALIZE_TIMESPEC(timespec);
436 #ifndef SLEEP_TIMESPEC
437 # define SLEEP_TIMESPEC(timespec) nanosleep(×pec, 0)
441 # define INIT_GROUPS(name, gid) ((setgid((gid)) == 0) && (initgroups((name), (gid)) == 0))
444 #ifndef PTHREAD_VALUE
445 # define PTHREAD_VALUE(t) (t)
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)
455 #ifndef PTHREAD_ATTR_DEFAULT
456 # define PTHREAD_ATTR_DEFAULT NULL
458 #ifndef PTHREAD_MUTEXATTR_DEFAULT
459 # define PTHREAD_MUTEXATTR_DEFAULT NULL
461 #ifndef PTHREAD_CONDATTR_DEFAULT
462 # define PTHREAD_CONDATTR_DEFAULT NULL
465 #ifndef PTHREAD_SIGACTION
466 # define PTHREAD_SIGACTION sigaction
470 # define STAT_PARENT lstat
473 /* socket options which might not be defined on all unx flavors */
474 #ifndef SO_ACCEPTCONN
475 # define SO_ACCEPTCONN 0
478 # define SO_SNDLOWAT 0
481 # define SO_RCVLOWAT 0
484 # define SO_SNDTIMEO 0
487 # define SO_RCVTIMEO 0
489 #ifndef SO_USELOOPBACK
490 # define SO_USELOOPBACK 0
492 #ifndef MSG_MAXIOVLEN
493 # define MSG_MAXIOVLEN 0
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
504 typedef struct sockaddr_ipx
{
508 unsigned short sa_socket
;
511 #define NSPROTO_IPX 1000
512 #define NSPROTO_SPX 1256
513 #define NSPROTO_SPXII 1257
517 #ifdef NO_PTHREAD_SEMAPHORES
521 pthread_mutex_t mutex
;
522 pthread_cond_t increased
;
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
);
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
);
546 #endif /* __OSL_SYSTEM_H__ */