164c51217SIngo Weinhold#ifndef BEOS_BUILD_COMPATIBILITY_H
264c51217SIngo Weinhold#define BEOS_BUILD_COMPATIBILITY_H
315694b30SIngo Weinhold
47a617f59SAugustin Cavalier// DEFFILEMODE is not available on platforms with MUSL
559c40b2fSMaurice Kalinowski#ifndef DEFFILEMODE
659c40b2fSMaurice Kalinowski#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
759c40b2fSMaurice Kalinowski#endif
859c40b2fSMaurice Kalinowski
937c10606SAugustin Cavalier// There's no ALLPERMS on platforms with MUSL
102284eb48SNiels Sascha Reedijk#ifndef ALLPERMS
112284eb48SNiels Sascha Reedijk#	define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
122284eb48SNiels Sascha Reedijk#endif
132284eb48SNiels Sascha Reedijk
1459c40b2fSMaurice Kalinowski#ifndef S_IUMSK
1559c40b2fSMaurice Kalinowski#define	S_IUMSK 07777
1659c40b2fSMaurice Kalinowski#endif
1759c40b2fSMaurice Kalinowski
18d34daac8SIngo Weinholdtypedef unsigned long	haiku_build_addr_t;
19d34daac8SIngo Weinhold#define addr_t			haiku_build_addr_t
2015694b30SIngo Weinhold
217a617f59SAugustin Cavalier#if defined(HAIKU_HOST_PLATFORM_MSYS)
227a617f59SAugustin Cavalier#define __addr_t_defined
237a617f59SAugustin Cavalier#endif
247a617f59SAugustin Cavalier
2515694b30SIngo Weinhold#include <Errors.h>
264c8f3064SIngo Weinhold
274c8f3064SIngo Weinhold#include <fcntl.h>
2855bc3719SIngo Weinhold#include <stdio.h>
2915694b30SIngo Weinhold#include <string.h>
3055bc3719SIngo Weinhold#include <sys/stat.h>
314c8f3064SIngo Weinhold#include <sys/types.h>
3255bc3719SIngo Weinhold#include <unistd.h>
33807304b1SAugustin Cavalier#include <sys/uio.h>
34807304b1SAugustin Cavalier
3515694b30SIngo Weinhold#ifdef __cplusplus
3615694b30SIngo Weinholdextern "C" {
3715694b30SIngo Weinhold#endif
3815694b30SIngo Weinhold
3915694b30SIngo Weinhold// Is kernel-only under Linux.
40a7d796e2SJonathan Schleifer#ifndef strlcpy
4164266621SAxel Dörflerextern size_t   strlcpy(char* dest, const char* source, size_t length);
42a7d796e2SJonathan Schleifer#endif
43a7d796e2SJonathan Schleifer#ifndef strlcat
4464266621SAxel Dörflerextern size_t	strlcat(char* dest, const char* source, size_t length);
45a7d796e2SJonathan Schleifer#endif
4615694b30SIngo Weinhold
476dcd0ccfSIngo Weinhold#if defined(HAIKU_HOST_PLATFORM_FREEBSD) || defined(HAIKU_HOST_PLATFORM_DARWIN)
4864266621SAxel Dörflerextern size_t	strnlen(const char* string, size_t length);
499f8734ebSAxel Dörfler#endif
509f8734ebSAxel Dörfler
5115694b30SIngo Weinhold// BeOS only
5264266621SAxel Dörflerextern ssize_t  read_pos(int fd, off_t pos, void* buffer, size_t count);
5364266621SAxel Dörflerextern ssize_t  write_pos(int fd, off_t pos, const void* buffer, size_t count);
5464266621SAxel Dörflerextern ssize_t	readv_pos(int fd, off_t pos, const struct iovec* vec,
55f38eff6aSIngo Weinhold					size_t count);
5664266621SAxel Dörflerextern ssize_t	writev_pos(int fd, off_t pos, const struct iovec* vec,
57f38eff6aSIngo Weinhold					size_t count);
5815694b30SIngo Weinhold
5915694b30SIngo Weinhold
6064266621SAxel Dörfler// There's no O_NOTRAVERSE under Linux and FreeBSD -- we replace it with a flag
6164266621SAxel Dörfler// that won't be used by our tools, preferrably a non-portable one; a fixed
6264266621SAxel Dörfler// constant could always lead to trouble on the host.
6364266621SAxel Dörfler// We can abuse this flag for our purposes as we filter it in libroot.
6415694b30SIngo Weinhold#ifndef O_NOTRAVERSE
6564266621SAxel Dörfler#	ifdef O_NOCTTY
6664266621SAxel Dörfler#		define O_NOTRAVERSE	O_NOCTTY
6764266621SAxel Dörfler#	elif defined(O_RANDOM)
6864266621SAxel Dörfler#		define O_NOTRAVERSE O_RANDOM
6964266621SAxel Dörfler#	else
7064266621SAxel Dörfler#		error "Search for a proper replacement value for O_NOTRAVERSE"
7164266621SAxel Dörfler#	endif
7215694b30SIngo Weinhold#endif
7315694b30SIngo Weinhold
7415694b30SIngo Weinhold#ifndef S_IUMSK
7564266621SAxel Dörfler#	define S_IUMSK ALLPERMS
7615694b30SIngo Weinhold#endif
7715694b30SIngo Weinhold
7815694b30SIngo Weinhold
7915694b30SIngo Weinhold// remap strerror()
8064266621SAxel Dörflerextern char* _haiku_build_strerror(int errnum);
8115694b30SIngo Weinhold
8215694b30SIngo Weinhold#ifndef BUILDING_HAIKU_ERROR_MAPPER
8315694b30SIngo Weinhold
8415694b30SIngo Weinhold#undef strerror
8515694b30SIngo Weinhold#define strerror(errnum)	_haiku_build_strerror(errnum)
8615694b30SIngo Weinhold
8764266621SAxel Dörfler#endif	// BUILDING_HAIKU_ERROR_MAPPER
8815694b30SIngo Weinhold
8955bc3719SIngo Weinhold
9055bc3719SIngo Weinhold// remap file descriptor functions
9155bc3719SIngo Weinholdint		_haiku_build_fchmod(int fd, mode_t mode);
9255bc3719SIngo Weinholdint		_haiku_build_fchmodat(int fd, const char* path, mode_t mode, int flag);
9355bc3719SIngo Weinholdint		_haiku_build_fstat(int fd, struct stat* st);
9455bc3719SIngo Weinholdint		_haiku_build_fstatat(int fd, const char* path, struct stat* st,
9555bc3719SIngo Weinhold			int flag);
9655bc3719SIngo Weinholdint		_haiku_build_mkdirat(int fd, const char* path, mode_t mode);
9755bc3719SIngo Weinholdint		_haiku_build_mkfifoat(int fd, const char* path, mode_t mode);
9855bc3719SIngo Weinholdint		_haiku_build_utimensat(int fd, const char* path,
9955bc3719SIngo Weinhold			const struct timespec times[2], int flag);
10055bc3719SIngo Weinholdint		_haiku_build_futimens(int fd, const struct timespec times[2]);
10155bc3719SIngo Weinholdint		_haiku_build_faccessat(int fd, const char* path, int accessMode,
10255bc3719SIngo Weinhold			int flag);
10355bc3719SIngo Weinholdint		_haiku_build_fchdir(int fd);
10455bc3719SIngo Weinholdint		_haiku_build_close(int fd);
10555bc3719SIngo Weinholdint		_haiku_build_dup(int fd);
10655bc3719SIngo Weinholdint		_haiku_build_dup2(int fd1, int fd2);
10755bc3719SIngo Weinholdint		_haiku_build_linkat(int toFD, const char* toPath, int pathFD,
10855bc3719SIngo Weinhold			const char* path, int flag);
10955bc3719SIngo Weinholdint		_haiku_build_unlinkat(int fd, const char* path, int flag);
11055bc3719SIngo Weinholdssize_t	_haiku_build_readlinkat(int fd, const char* path, char* buffer,
11155bc3719SIngo Weinhold			size_t bufferSize);
11255bc3719SIngo Weinholdint		_haiku_build_symlinkat(const char* toPath, int fd,
11355bc3719SIngo Weinhold			const char* symlinkPath);
11455bc3719SIngo Weinholdint		_haiku_build_ftruncate(int fd, off_t newSize);
11555bc3719SIngo Weinholdint		_haiku_build_fchown(int fd, uid_t owner, gid_t group);
11655bc3719SIngo Weinholdint		_haiku_build_fchownat(int fd, const char* path, uid_t owner,
11755bc3719SIngo Weinhold			gid_t group, int flag);
11855bc3719SIngo Weinholdint		_haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev);
11955bc3719SIngo Weinholdint		_haiku_build_creat(const char* path, mode_t mode);
12055bc3719SIngo Weinhold#ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
12155bc3719SIngo Weinholdint		_haiku_build_open(const char* path, int openMode, ...);
12255bc3719SIngo Weinholdint		_haiku_build_openat(int fd, const char* path, int openMode, ...);
12355bc3719SIngo Weinholdint		_haiku_build_fcntl(int fd, int op, ...);
12455bc3719SIngo Weinhold#else
12555bc3719SIngo Weinholdint		_haiku_build_open(const char* path, int openMode, mode_t permissions);
12655bc3719SIngo Weinholdint		_haiku_build_openat(int fd, const char* path, int openMode,
12755bc3719SIngo Weinhold			mode_t permissions);
12855bc3719SIngo Weinholdint		_haiku_build_fcntl(int fd, int op, int argument);
12955bc3719SIngo Weinhold#endif
13055bc3719SIngo Weinholdint		_haiku_build_renameat(int fromFD, const char* from, int toFD,
13155bc3719SIngo Weinhold			const char* to);
13255bc3719SIngo Weinhold
13355bc3719SIngo Weinhold#ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
13455bc3719SIngo Weinhold#	define fchmod(fd, mode)				_haiku_build_fchmod(fd, mode)
13555bc3719SIngo Weinhold#	define fchmodat(fd, path, mode, flag) \
13655bc3719SIngo Weinhold		_haiku_build_fchmodat(fd, path, mode, flag)
13755bc3719SIngo Weinhold#	define fstat(fd, st)				_haiku_build_fstat(fd, st)
13855bc3719SIngo Weinhold#	define fstatat(fd, path, st, flag)	_haiku_build_fstatat(fd, path, st, flag)
13955bc3719SIngo Weinhold#	define mkdirat(fd, path, mode)		_haiku_build_mkdirat(fd, path, mode)
14055bc3719SIngo Weinhold#	define mkfifoat(fd, path, mode)		_haiku_build_mkfifoat(fd, path, mode)
14155bc3719SIngo Weinhold#	define utimensat(fd, path, times, flag) \
14255bc3719SIngo Weinhold		_haiku_build_utimensat(fd, path, times, flag)
14355bc3719SIngo Weinhold#	define futimens(fd, times)			_haiku_build_futimens(fd, times)
14455bc3719SIngo Weinhold#	define faccessat(fd, path, accessMode, flag) \
14555bc3719SIngo Weinhold		_haiku_build_faccessat(fd, path, accessMode, flag)
14655bc3719SIngo Weinhold#	define fchdir(fd)					_haiku_build_fchdir(fd)
14755bc3719SIngo Weinhold#	define close(fd)					_haiku_build_close(fd)
14855bc3719SIngo Weinhold#	define dup(fd)						_haiku_build_dup(fd)
14955bc3719SIngo Weinhold#	define dup2(fd1, fd2)				_haiku_build_dup2(fd1, fd2)
15055bc3719SIngo Weinhold#	define linkat(toFD, toPath, pathFD, path, flag) \
15155bc3719SIngo Weinhold		_haiku_build_linkat(toFD, toPath, pathFD, path, flag)
15255bc3719SIngo Weinhold#	define unlinkat(fd, path, flag)		_haiku_build_unlinkat(fd, path, flag)
15355bc3719SIngo Weinhold#	define readlinkat(fd, path, buffer, bufferSize) \
15455bc3719SIngo Weinhold		_haiku_build_readlinkat(fd, path, buffer, bufferSize)
15555bc3719SIngo Weinhold#	define symlinkat(toPath, fd, symlinkPath) \
15655bc3719SIngo Weinhold		_haiku_build_symlinkat(toPath, fd, symlinkPath)
15755bc3719SIngo Weinhold#	define ftruncate(fd, newSize)		_haiku_build_ftruncate(fd, newSize)
15855bc3719SIngo Weinhold#	define fchown(fd, owner, group)		_haiku_build_fchown(fd, owner, group)
15955bc3719SIngo Weinhold#	define fchownat(fd, path, owner, group, flag) \
16055bc3719SIngo Weinhold		_haiku_build_fchownat(fd, path, owner, group, flag)
16155bc3719SIngo Weinhold#	define mknodat(fd, name, mode, dev) \
16255bc3719SIngo Weinhold		_haiku_build_mknodat(fd, name, mode, dev)
16355bc3719SIngo Weinhold#	define creat(path, mode)			_haiku_build_creat(path, mode)
16455bc3719SIngo Weinhold#	define open(path, openMode...)		_haiku_build_open(path, openMode)
16555bc3719SIngo Weinhold#	define openat(fd, path, openMode...) \
16655bc3719SIngo Weinhold		_haiku_build_openat(fd, path, openMode)
16755bc3719SIngo Weinhold#	define fcntl(fd, op...)				_haiku_build_fcntl(fd, op)
16855bc3719SIngo Weinhold#	define renameat(fromFD, from, toFD, to) \
16955bc3719SIngo Weinhold		_haiku_build_renameat(fromFD, from, toFD, to)
170648f0d5fSAugustin Cavalier
171648f0d5fSAugustin Cavalier#	if defined(HAIKU_HOST_USE_XATTR) && defined(HAIKU_HOST_PLATFORM_HAIKU)
172648f0d5fSAugustin Cavalier#		define fs_read_attr			_haiku_build_fs_read_attr
173648f0d5fSAugustin Cavalier#		define fs_write_attr		_haiku_build_fs_write_attr
174648f0d5fSAugustin Cavalier#		define fs_remove_attr		_haiku_build_fs_remove_attr
175648f0d5fSAugustin Cavalier#		define fs_stat_attr			_haiku_build_fs_stat_attr
176648f0d5fSAugustin Cavalier#		define fs_open_attr			_haiku_build_fs_open_attr
177648f0d5fSAugustin Cavalier#		define fs_fopen_attr		_haiku_build_fs_fopen_attr
178648f0d5fSAugustin Cavalier#		define fs_close_attr		_haiku_build_fs_close_attr
179648f0d5fSAugustin Cavalier#		define fs_open_attr_dir		_haiku_build_fs_open_attr_dir
180648f0d5fSAugustin Cavalier#		define fs_fopen_attr_dir	_haiku_build_fs_fopen_attr_dir
181648f0d5fSAugustin Cavalier#		define fs_close_attr_dir	_haiku_build_fs_close_attr_dir
182648f0d5fSAugustin Cavalier#		define fs_read_attr_dir		_haiku_build_fs_read_attr_dir
183648f0d5fSAugustin Cavalier#		define fs_rewind_attr_dir	_haiku_build_fs_rewind_attr_dir
184648f0d5fSAugustin Cavalier#	endif
185648f0d5fSAugustin Cavalier
18655bc3719SIngo Weinhold#endif	// _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
18755bc3719SIngo Weinhold
18855bc3719SIngo Weinhold
18915694b30SIngo Weinhold#ifdef __cplusplus
19015694b30SIngo Weinhold} // extern "C"
19115694b30SIngo Weinhold#endif
19215694b30SIngo Weinhold
19364c51217SIngo Weinhold#endif	// BEOS_BUILD_COMPATIBILITY_H
19415694b30SIngo Weinhold
195