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