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