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