1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef __OSL_SYSTEM_H__
21#define __OSL_SYSTEM_H__
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <limits.h>
26#include <string.h>
27#include <errno.h>
28#include <stdarg.h>
29
30#include <unistd.h>
31#include <fcntl.h>
32#include <dirent.h>
33#include <signal.h>
34#include <utime.h>
35
36#include <pwd.h>
37
38#include <netdb.h>
39
40#include <sys/stat.h>
41#include <sys/wait.h>
42
43#include <sys/types.h>
44
45/* Make sockets of type AF_UNIX use underlying FS rights */
46#ifdef SOLARIS
47# define _XOPEN_SOURCE 500
48# include <sys/socket.h>
49# undef _XOPEN_SOURCE
50#else
51# include <sys/socket.h>
52#endif
53
54#include <netinet/in.h>
55#include <arpa/inet.h>
56
57#ifdef SYSV
58# include <sys/utsname.h>
59#endif
60
61#ifdef LINUX
62# ifndef __USE_GNU
63# define __USE_GNU
64# endif
65
66# include <shadow.h>
67# include <pthread.h>
68# include <sys/file.h>
69# include <sys/ioctl.h>
70# include <sys/uio.h>
71# include <sys/un.h>
72# include <netinet/tcp.h>
73# include <dlfcn.h>
74# include <endian.h>
75# include <sys/time.h>
76# if __BYTE_ORDER == __LITTLE_ENDIAN
77# define _LITTLE_ENDIAN
78# elif __BYTE_ORDER == __BIG_ENDIAN
79# ifndef _BIG_ENDIAN
80# define _BIG_ENDIAN
81# endif
82# endif
83# define IORESOURCE_TRANSFER_BSD
84# define IOCHANNEL_TRANSFER_BSD_RENO
85# define pthread_testcancel()
86# define NO_PTHREAD_PRIORITY
87# define PTHREAD_SIGACTION pthread_sigaction
88
89# ifndef ETIME
90# define ETIME ETIMEDOUT
91# endif
92
93#endif
94
95#ifdef ANDROID
96# include <pthread.h>
97# include <sys/file.h>
98# include <sys/ioctl.h>
99# include <sys/uio.h>
100# include <sys/un.h>
101# include <netinet/tcp.h>
102# include <dlfcn.h>
103# include <endian.h>
104# include <sys/time.h>
105# define IORESOURCE_TRANSFER_BSD
106# define IOCHANNEL_TRANSFER_BSD_RENO
107# define pthread_testcancel()
108# define NO_PTHREAD_PRIORITY
109#endif
110
111#ifdef NETBSD
112# define NO_PTHREAD_RTL
113#endif
114
115#ifdef FREEBSD
116# define ETIME ETIMEDOUT
117# include <pthread.h>
118# include <sys/sem.h>
119# include <dlfcn.h>
120# include <sys/filio.h>
121# include <sys/ioctl.h>
122# include <sys/param.h>
123# include <sys/time.h>
124# include <sys/uio.h>
125# include <sys/exec.h>
126# include <vm/vm.h>
127# include <vm/vm_param.h>
128# include <vm/pmap.h>
129# include <vm/swap_pager.h>
130# include <sys/un.h>
131# include <netinet/tcp.h>
132# define IORESOURCE_TRANSFER_BSD
133# include <machine/endian.h>
134#if __FreeBSD_version < 500000
135# if BYTE_ORDER == LITTLE_ENDIAN
136# define _LITTLE_ENDIAN
137# elif BYTE_ORDER == BIG_ENDIAN
138# define _BIG_ENDIAN
139# endif
140#endif
141# define NO_PTHREAD_RTL
142#endif
143
144#ifdef OPENBSD
145# define ETIME ETIMEDOUT
146# include <pthread.h>
147# include <sys/sem.h>
148# include <dlfcn.h>
149# include <sys/filio.h>
150# include <sys/ioctl.h>
151# include <sys/param.h>
152# include <sys/time.h>
153# include <sys/uio.h>
154# include <sys/exec.h>
155# include <sys/un.h>
156# include <netinet/tcp.h>
157# define IORESOURCE_TRANSFER_BSD
158# include <machine/endian.h>
159# define PTR_SIZE_T(s) ((size_t *)&(s))
160# define IORESOURCE_TRANSFER_BSD
161# define IOCHANNEL_TRANSFER_BSD_RENO
162# define pthread_testcancel()
163# define NO_PTHREAD_PRIORITY
164# define NO_PTHREAD_RTL
165# define PTHREAD_SIGACTION pthread_sigaction
166#endif
167
168#if defined(DRAGONFLY) || defined(NETBSD)
169# define ETIME ETIMEDOUT
170# include <pthread.h>
171# include <sys/sem.h>
172# include <dlfcn.h>
173# include <sys/filio.h>
174# include <sys/ioctl.h>
175# include <sys/param.h>
176# include <sys/time.h>
177# include <sys/uio.h>
178# include <sys/exec.h>
179# include <sys/un.h>
180# include <netinet/tcp.h>
181# include <machine/endian.h>
182# define IORESOURCE_TRANSFER_BSD
183# define IOCHANNEL_TRANSFER_BSD_RENO
184#endif
185
186#ifdef AIX
187# define AF_IPX -1
188# include <strings.h>
189# include <pthread.h>
190# include <dlfcn.h>
191# include <sys/time.h>
192# include <sys/un.h>
193# include <netinet/tcp.h>
194# include <sys/machine.h>
195# if BYTE_ORDER == LITTLE_ENDIAN
196# ifndef _LITTLE_ENDIAN
197# define _LITTLE_ENDIAN
198# endif
199# elif BYTE_ORDER == BIG_ENDIAN
200# ifndef _BIG_ENDIAN
201# define _BIG_ENDIAN
202# endif
203# endif
204# define SLEEP_TIMESPEC(timespec) nsleep(&timespec, 0)
205# define LIBPATH "LIBPATH"
206#endif
207
208#ifdef SOLARIS
209# include <shadow.h>
210# include <sys/un.h>
211# include <stropts.h>
212# include <pthread.h>
213# include <netinet/tcp.h>
214# include <sys/filio.h>
215# include <dlfcn.h>
216# include <sys/isa_defs.h>
217# define IORESOURCE_TRANSFER_SYSV
218# define IOCHANNEL_TRANSFER_BSD
219# define LIBPATH "LD_LIBRARY_PATH"
220#endif
221
222#ifdef MACOSX
223#define __OPENTRANSPORTPROVIDERS__ // these are already defined
224#define TimeValue CFTimeValue // Do not conflict with TimeValue in sal/inc/osl/time.h
225#include <Carbon/Carbon.h>
226#undef TimeValue
227# ifndef ETIME
228# define ETIME ETIMEDOUT
229# endif
230# include <dlfcn.h>
231# include <pthread.h>
232# include <sys/file.h>
233# include <sys/ioctl.h>
234# include <sys/uio.h>
235# include <sys/un.h>
236# include <netinet/tcp.h>
237# include <machine/endian.h>
238# include <sys/time.h>
239/* fixme are premac and postmac still needed here? */
240# include <premac.h>
241# include <mach-o/dyld.h>
242# include <postmac.h>
243# if BYTE_ORDER == LITTLE_ENDIAN
244# ifndef _LITTLE_ENDIAN
245# define _LITTLE_ENDIAN
246# endif
247# elif BYTE_ORDER == BIG_ENDIAN
248# ifndef _BIG_ENDIAN
249# define _BIG_ENDIAN
250# endif
251# endif
252# define IOCHANNEL_TRANSFER_BSD_RENO
253# define NO_PTHREAD_RTL
254/* for NSGetArgc/Argv/Environ */
255# include <crt_externs.h>
256#ifdef __cplusplus
257extern "C" {
258#endif
259int macxp_resolveAlias(char *path, int buflen);
260#ifdef __cplusplus
261}
262#endif
263#endif
264
265#ifdef IOS
266# ifndef ETIME
267# define ETIME ETIMEDOUT
268# endif
269# include <dlfcn.h>
270# include <pthread.h>
271# include <sys/file.h>
272# include <sys/ioctl.h>
273# include <sys/uio.h>
274# include <sys/un.h>
275# include <netinet/tcp.h>
276# include <machine/endian.h>
277# include <sys/time.h>
278# if BYTE_ORDER == LITTLE_ENDIAN
279# ifndef _LITTLE_ENDIAN
280# define _LITTLE_ENDIAN
281# endif
282# elif BYTE_ORDER == BIG_ENDIAN
283# ifndef _BIG_ENDIAN
284# define _BIG_ENDIAN
285# endif
286# endif
287# define IOCHANNEL_TRANSFER_BSD_RENO
288# define NO_PTHREAD_RTL
289#endif
290
291#if !defined(_WIN32) && \
292 !defined(LINUX) && !defined(NETBSD) && !defined(FREEBSD) && \
293 !defined(AIX) && \
294 !defined(SOLARIS) && !defined(MACOSX) && \
295 !defined(OPENBSD) && !defined(DRAGONFLY) && \
296 !defined(IOS) && !defined(ANDROID)
297# error "Target platform not specified!"
298#endif
299
300#ifndef PTR_FD_SET
301# define PTR_FD_SET(s) (&(s))
302#endif
303
304#ifndef NORMALIZE_TIMESPEC
305# define NORMALIZE_TIMESPEC(timespec) \
306 timespec . tv_sec += timespec . tv_nsec / 1000000000; \
307 timespec . tv_nsec %= 1000000000;
308#endif
309
310#ifndef SET_TIMESPEC
311# define SET_TIMESPEC(timespec, sec, nsec) \
312 timespec . tv_sec = (sec); \
313 timespec . tv_nsec = (nsec); \
314 NORMALIZE_TIMESPEC(timespec);
315#endif
316
317#ifndef SLEEP_TIMESPEC
318# define SLEEP_TIMESPEC(timespec) nanosleep(&timespec, 0)
319#endif
320
321#ifndef INIT_GROUPS
322# define INIT_GROUPS(name, gid) ((setgid((gid)) == 0) && (initgroups((name), (gid)) == 0))
323#endif
324
325#ifndef PTHREAD_VALUE
326# define PTHREAD_VALUE(t) (t)
327#endif
328#ifndef PTHREAD_NONE
329# define PTHREAD_NONE _pthread_none_
330# ifndef PTHREAD_NONE_INIT
331# define PTHREAD_NONE_INIT ((pthread_t)-1)
332# endif
333#endif
334
335#ifndef PTHREAD_ATTR_DEFAULT
336# define PTHREAD_ATTR_DEFAULT NULL
337#endif
338#ifndef PTHREAD_MUTEXATTR_DEFAULT
339# define PTHREAD_MUTEXATTR_DEFAULT NULL
340#endif
341#ifndef PTHREAD_CONDATTR_DEFAULT
342# define PTHREAD_CONDATTR_DEFAULT NULL
343#endif
344
345#ifndef PTHREAD_SIGACTION
346# define PTHREAD_SIGACTION sigaction
347#endif
348
349#ifndef STAT_PARENT
350# define STAT_PARENT lstat
351#endif
352
353/* socket options which might not be defined on all unx flavors */
354#ifndef SO_ACCEPTCONN
355# define SO_ACCEPTCONN 0
356#endif
357#ifndef SO_SNDLOWAT
358# define SO_SNDLOWAT 0
359#endif
360#ifndef SO_RCVLOWAT
361# define SO_RCVLOWAT 0
362#endif
363#ifndef SO_SNDTIMEO
364# define SO_SNDTIMEO 0
365#endif
366#ifndef SO_RCVTIMEO
367# define SO_RCVTIMEO 0
368#endif
369#ifndef SO_USELOOPBACK
370# define SO_USELOOPBACK 0
371#endif
372#ifndef MSG_MAXIOVLEN
373# define MSG_MAXIOVLEN 0
374#endif
375
376/* BEGIN HACK */
377/* dummy define and declarations for IPX should be replaced by */
378/* original ipx headers when these are available for this platform */
379
380#ifndef SA_FAMILY_DECL
381# define SA_FAMILY_DECL short sa_family
382#endif
383
384typedef struct sockaddr_ipx {
385 SA_FAMILY_DECL;
386 char sa_netnum[4];
387 char sa_nodenum[6];
388 unsigned short sa_socket;
389} SOCKADDR_IPX;
390
391#define NSPROTO_IPX 1000
392#define NSPROTO_SPX 1256
393#define NSPROTO_SPXII 1257
394
395/* END HACK */
396
397#ifdef NO_PTHREAD_RTL
398#if !defined FREEBSD || (__FreeBSD_version < 500112)
399#if !defined NETBSD
400struct passwd *getpwent_r(struct passwd *pwd, char *buffer, int buflen);
401#endif
402extern struct spwd *getspnam_r(const char *name, struct spwd *result,
403 char *buffer, int buflen);
404
405struct tm *localtime_r(const time_t *timep, struct tm *buffer);
406struct tm *gmtime_r(const time_t *timep, struct tm *buffer);
407#endif /* !defined FREEBSD || (__FreeBSD_version < 500112) */
408#if !defined(FREEBSD) || (__FreeBSD_version < 601103)
409struct hostent *gethostbyname_r(const char *name, struct hostent *result,
410 char *buffer, size_t buflen, int *h_errnop);
411#endif /* !defined(FREEBSD) || (__FreeBSD_version < 601103) */
412#endif
413
414#endif /* __OSL_SYSTEM_H__ */
415
416/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
417