BeOSBuildCompatibility.h revision 648f0d5f
1#ifndef BEOS_BUILD_COMPATIBILITY_H
2#define BEOS_BUILD_COMPATIBILITY_H
3
4#if defined(HAIKU_HOST_PLATFORM_CYGWIN)
5#	ifndef __addr_t_defined
6#		define __addr_t_defined
7#	endif
8#endif
9
10#if defined(HAIKU_HOST_PLATFORM_CYGWIN) || defined(HAIKU_HOST_PLATFORM_SUNOS)
11#ifndef DEFFILEMODE
12#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
13#endif
14
15#ifndef S_IUMSK
16#define	S_IUMSK 07777
17#endif
18
19#include <ctype.h>
20#endif
21
22#ifdef HAIKU_HOST_PLATFORM_SUNOS
23#	include <limits.h>
24#	ifndef NAME_MAX
25#		define NAME_MAX	MAXNAMELEN
26#	endif
27#endif
28
29typedef unsigned long	haiku_build_addr_t;
30#define addr_t			haiku_build_addr_t
31
32#include <Errors.h>
33
34#include <fcntl.h>
35#include <stdio.h>
36#include <string.h>
37#include <sys/stat.h>
38#include <sys/types.h>
39#include <sys/uio.h>
40#include <unistd.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46// Is kernel-only under Linux.
47#ifndef strlcpy
48extern size_t   strlcpy(char* dest, const char* source, size_t length);
49#endif
50#ifndef strlcat
51extern size_t	strlcat(char* dest, const char* source, size_t length);
52#endif
53
54#if defined(HAIKU_HOST_PLATFORM_FREEBSD) || defined(HAIKU_HOST_PLATFORM_DARWIN)
55extern size_t	strnlen(const char* string, size_t length);
56#endif
57
58#if defined(HAIKU_HOST_PLATFORM_CYGWIN) || defined(HAIKU_HOST_PLATFORM_SUNOS)
59extern char*	stpcpy(char* dest, const char* src);
60extern char*	strcasestr(const char* s, const char* find);
61#endif
62
63// BeOS only
64extern ssize_t  read_pos(int fd, off_t pos, void* buffer, size_t count);
65extern ssize_t  write_pos(int fd, off_t pos, const void* buffer, size_t count);
66extern ssize_t	readv_pos(int fd, off_t pos, const struct iovec* vec,
67					size_t count);
68extern ssize_t	writev_pos(int fd, off_t pos, const struct iovec* vec,
69					size_t count);
70
71
72// There's no O_NOTRAVERSE under Linux and FreeBSD -- we replace it with a flag
73// that won't be used by our tools, preferrably a non-portable one; a fixed
74// constant could always lead to trouble on the host.
75// We can abuse this flag for our purposes as we filter it in libroot.
76#ifndef O_NOTRAVERSE
77#	ifdef O_NOCTTY
78#		define O_NOTRAVERSE	O_NOCTTY
79#	elif defined(O_RANDOM)
80#		define O_NOTRAVERSE O_RANDOM
81#	else
82#		error "Search for a proper replacement value for O_NOTRAVERSE"
83#	endif
84#endif
85
86#ifndef S_IUMSK
87#	define S_IUMSK ALLPERMS
88#endif
89
90
91// remap strerror()
92extern char* _haiku_build_strerror(int errnum);
93
94#ifndef BUILDING_HAIKU_ERROR_MAPPER
95
96#undef strerror
97#define strerror(errnum)	_haiku_build_strerror(errnum)
98
99#endif	// BUILDING_HAIKU_ERROR_MAPPER
100
101
102// remap file descriptor functions
103int		_haiku_build_fchmod(int fd, mode_t mode);
104int		_haiku_build_fchmodat(int fd, const char* path, mode_t mode, int flag);
105int		_haiku_build_fstat(int fd, struct stat* st);
106int		_haiku_build_fstatat(int fd, const char* path, struct stat* st,
107			int flag);
108int		_haiku_build_mkdirat(int fd, const char* path, mode_t mode);
109int		_haiku_build_mkfifoat(int fd, const char* path, mode_t mode);
110int		_haiku_build_utimensat(int fd, const char* path,
111			const struct timespec times[2], int flag);
112int		_haiku_build_futimens(int fd, const struct timespec times[2]);
113int		_haiku_build_faccessat(int fd, const char* path, int accessMode,
114			int flag);
115int		_haiku_build_fchdir(int fd);
116int		_haiku_build_close(int fd);
117int		_haiku_build_dup(int fd);
118int		_haiku_build_dup2(int fd1, int fd2);
119int		_haiku_build_linkat(int toFD, const char* toPath, int pathFD,
120			const char* path, int flag);
121int		_haiku_build_unlinkat(int fd, const char* path, int flag);
122ssize_t	_haiku_build_readlinkat(int fd, const char* path, char* buffer,
123			size_t bufferSize);
124int		_haiku_build_symlinkat(const char* toPath, int fd,
125			const char* symlinkPath);
126int		_haiku_build_ftruncate(int fd, off_t newSize);
127int		_haiku_build_fchown(int fd, uid_t owner, gid_t group);
128int		_haiku_build_fchownat(int fd, const char* path, uid_t owner,
129			gid_t group, int flag);
130int		_haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev);
131int		_haiku_build_creat(const char* path, mode_t mode);
132#ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
133int		_haiku_build_open(const char* path, int openMode, ...);
134int		_haiku_build_openat(int fd, const char* path, int openMode, ...);
135int		_haiku_build_fcntl(int fd, int op, ...);
136#else
137int		_haiku_build_open(const char* path, int openMode, mode_t permissions);
138int		_haiku_build_openat(int fd, const char* path, int openMode,
139			mode_t permissions);
140int		_haiku_build_fcntl(int fd, int op, int argument);
141#endif
142int		_haiku_build_renameat(int fromFD, const char* from, int toFD,
143			const char* to);
144
145#ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
146#	define fchmod(fd, mode)				_haiku_build_fchmod(fd, mode)
147#	define fchmodat(fd, path, mode, flag) \
148		_haiku_build_fchmodat(fd, path, mode, flag)
149#	define fstat(fd, st)				_haiku_build_fstat(fd, st)
150#	define fstatat(fd, path, st, flag)	_haiku_build_fstatat(fd, path, st, flag)
151#	define mkdirat(fd, path, mode)		_haiku_build_mkdirat(fd, path, mode)
152#	define mkfifoat(fd, path, mode)		_haiku_build_mkfifoat(fd, path, mode)
153#	define utimensat(fd, path, times, flag) \
154		_haiku_build_utimensat(fd, path, times, flag)
155#	define futimens(fd, times)			_haiku_build_futimens(fd, times)
156#	define faccessat(fd, path, accessMode, flag) \
157		_haiku_build_faccessat(fd, path, accessMode, flag)
158#	define fchdir(fd)					_haiku_build_fchdir(fd)
159#	define close(fd)					_haiku_build_close(fd)
160#	define dup(fd)						_haiku_build_dup(fd)
161#	define dup2(fd1, fd2)				_haiku_build_dup2(fd1, fd2)
162#	define linkat(toFD, toPath, pathFD, path, flag) \
163		_haiku_build_linkat(toFD, toPath, pathFD, path, flag)
164#	define unlinkat(fd, path, flag)		_haiku_build_unlinkat(fd, path, flag)
165#	define readlinkat(fd, path, buffer, bufferSize) \
166		_haiku_build_readlinkat(fd, path, buffer, bufferSize)
167#	define symlinkat(toPath, fd, symlinkPath) \
168		_haiku_build_symlinkat(toPath, fd, symlinkPath)
169#	define ftruncate(fd, newSize)		_haiku_build_ftruncate(fd, newSize)
170#	define fchown(fd, owner, group)		_haiku_build_fchown(fd, owner, group)
171#	define fchownat(fd, path, owner, group, flag) \
172		_haiku_build_fchownat(fd, path, owner, group, flag)
173#	define mknodat(fd, name, mode, dev) \
174		_haiku_build_mknodat(fd, name, mode, dev)
175#	define creat(path, mode)			_haiku_build_creat(path, mode)
176#	define open(path, openMode...)		_haiku_build_open(path, openMode)
177#	define openat(fd, path, openMode...) \
178		_haiku_build_openat(fd, path, openMode)
179#	define fcntl(fd, op...)				_haiku_build_fcntl(fd, op)
180#	define renameat(fromFD, from, toFD, to) \
181		_haiku_build_renameat(fromFD, from, toFD, to)
182
183#	if defined(HAIKU_HOST_USE_XATTR) && defined(HAIKU_HOST_PLATFORM_HAIKU)
184#		define fs_read_attr			_haiku_build_fs_read_attr
185#		define fs_write_attr		_haiku_build_fs_write_attr
186#		define fs_remove_attr		_haiku_build_fs_remove_attr
187#		define fs_stat_attr			_haiku_build_fs_stat_attr
188#		define fs_open_attr			_haiku_build_fs_open_attr
189#		define fs_fopen_attr		_haiku_build_fs_fopen_attr
190#		define fs_close_attr		_haiku_build_fs_close_attr
191#		define fs_open_attr_dir		_haiku_build_fs_open_attr_dir
192#		define fs_fopen_attr_dir	_haiku_build_fs_fopen_attr_dir
193#		define fs_close_attr_dir	_haiku_build_fs_close_attr_dir
194#		define fs_read_attr_dir		_haiku_build_fs_read_attr_dir
195#		define fs_rewind_attr_dir	_haiku_build_fs_rewind_attr_dir
196#	endif
197
198#endif	// _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
199
200
201#ifdef __cplusplus
202} // extern "C"
203#endif
204
205#endif	// BEOS_BUILD_COMPATIBILITY_H
206
207