164c51217SIngo Weinhold#ifndef BEOS_BUILD_COMPATIBILITY_H
264c51217SIngo Weinhold#define BEOS_BUILD_COMPATIBILITY_H
315694b30SIngo Weinhold
4807304b1SAugustin Cavalier// These things have to be done before anything is included
5807304b1SAugustin Cavalier#if defined(HAIKU_HOST_PLATFORM_MINGW)
6807304b1SAugustin Cavalier#define _MODE_T_
7807304b1SAugustin Cavalier#define _POSIX_
8807304b1SAugustin Cavaliertypedef int mode_t;
9807304b1SAugustin Cavalier
10807304b1SAugustin Cavalier#include <stdint.h>
11807304b1SAugustin Cavalier#include <limits.h>
12807304b1SAugustin Cavaliertypedef uint32_t uid_t;
13807304b1SAugustin Cavaliertypedef uint32_t gid_t;
14807304b1SAugustin Cavalier
15807304b1SAugustin Cavalier#include <io.h>
16807304b1SAugustin Cavalier#define mkdir(path, mode) mkdir(path)
17807304b1SAugustin Cavalier#endif
18807304b1SAugustin Cavalier
1937c10606SAugustin Cavalier// DEFFILEMODE is not available on MinGW and on platforms with MUSL
2059c40b2fSMaurice Kalinowski#ifndef DEFFILEMODE
2159c40b2fSMaurice Kalinowski#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
2259c40b2fSMaurice Kalinowski#endif
2359c40b2fSMaurice Kalinowski
2437c10606SAugustin Cavalier// There's no ALLPERMS on platforms with MUSL
252284eb48SNiels Sascha Reedijk#ifndef ALLPERMS
262284eb48SNiels Sascha Reedijk#	define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
272284eb48SNiels Sascha Reedijk#endif
282284eb48SNiels Sascha Reedijk
2959c40b2fSMaurice Kalinowski#ifndef S_IUMSK
3059c40b2fSMaurice Kalinowski#define	S_IUMSK 07777
3159c40b2fSMaurice Kalinowski#endif
3259c40b2fSMaurice Kalinowski
33d34daac8SIngo Weinholdtypedef unsigned long	haiku_build_addr_t;
34d34daac8SIngo Weinhold#define addr_t			haiku_build_addr_t
3515694b30SIngo Weinhold
3615694b30SIngo Weinhold#include <Errors.h>
374c8f3064SIngo Weinhold
384c8f3064SIngo Weinhold#include <fcntl.h>
3955bc3719SIngo Weinhold#include <stdio.h>
4015694b30SIngo Weinhold#include <string.h>
4155bc3719SIngo Weinhold#include <sys/stat.h>
424c8f3064SIngo Weinhold#include <sys/types.h>
4355bc3719SIngo Weinhold#include <unistd.h>
4415694b30SIngo Weinhold
45807304b1SAugustin Cavalier#if !defined(HAIKU_HOST_PLATFORM_MINGW)
46807304b1SAugustin Cavalier#include <sys/uio.h>
47807304b1SAugustin Cavalier#endif
48807304b1SAugustin Cavalier
4915694b30SIngo Weinhold#ifdef __cplusplus
5015694b30SIngo Weinholdextern "C" {
5115694b30SIngo Weinhold#endif
5215694b30SIngo Weinhold
5315694b30SIngo Weinhold// Is kernel-only under Linux.
54a7d796e2SJonathan Schleifer#ifndef strlcpy
5564266621SAxel Dörflerextern size_t   strlcpy(char* dest, const char* source, size_t length);
56a7d796e2SJonathan Schleifer#endif
57a7d796e2SJonathan Schleifer#ifndef strlcat
5864266621SAxel Dörflerextern size_t	strlcat(char* dest, const char* source, size_t length);
59a7d796e2SJonathan Schleifer#endif
6015694b30SIngo Weinhold
616dcd0ccfSIngo Weinhold#if defined(HAIKU_HOST_PLATFORM_FREEBSD) || defined(HAIKU_HOST_PLATFORM_DARWIN)
6264266621SAxel Dörflerextern size_t	strnlen(const char* string, size_t length);
639f8734ebSAxel Dörfler#endif
649f8734ebSAxel Dörfler
6537c10606SAugustin Cavalier#if defined(HAIKU_HOST_PLATFORM_MINGW)
6664266621SAxel Dörflerextern char*	stpcpy(char* dest, const char* src);
6764266621SAxel Dörflerextern char*	strcasestr(const char* s, const char* find);
6859c40b2fSMaurice Kalinowski#endif
6959c40b2fSMaurice Kalinowski
7015694b30SIngo Weinhold// BeOS only
7164266621SAxel Dörflerextern ssize_t  read_pos(int fd, off_t pos, void* buffer, size_t count);
7264266621SAxel Dörflerextern ssize_t  write_pos(int fd, off_t pos, const void* buffer, size_t count);
7364266621SAxel Dörflerextern ssize_t	readv_pos(int fd, off_t pos, const struct iovec* vec,
74f38eff6aSIngo Weinhold					size_t count);
7564266621SAxel Dörflerextern ssize_t	writev_pos(int fd, off_t pos, const struct iovec* vec,
76f38eff6aSIngo Weinhold					size_t count);
7715694b30SIngo Weinhold
7815694b30SIngo Weinhold
7964266621SAxel Dörfler// There's no O_NOTRAVERSE under Linux and FreeBSD -- we replace it with a flag
8064266621SAxel Dörfler// that won't be used by our tools, preferrably a non-portable one; a fixed
8164266621SAxel Dörfler// constant could always lead to trouble on the host.
8264266621SAxel Dörfler// We can abuse this flag for our purposes as we filter it in libroot.
8315694b30SIngo Weinhold#ifndef O_NOTRAVERSE
8464266621SAxel Dörfler#	ifdef O_NOCTTY
8564266621SAxel Dörfler#		define O_NOTRAVERSE	O_NOCTTY
8664266621SAxel Dörfler#	elif defined(O_RANDOM)
8764266621SAxel Dörfler#		define O_NOTRAVERSE O_RANDOM
8864266621SAxel Dörfler#	else
8964266621SAxel Dörfler#		error "Search for a proper replacement value for O_NOTRAVERSE"
9064266621SAxel Dörfler#	endif
9115694b30SIngo Weinhold#endif
9215694b30SIngo Weinhold
9315694b30SIngo Weinhold#ifndef S_IUMSK
9464266621SAxel Dörfler#	define S_IUMSK ALLPERMS
9515694b30SIngo Weinhold#endif
9615694b30SIngo Weinhold
9715694b30SIngo Weinhold
9815694b30SIngo Weinhold// remap strerror()
9964266621SAxel Dörflerextern char* _haiku_build_strerror(int errnum);
10015694b30SIngo Weinhold
10115694b30SIngo Weinhold#ifndef BUILDING_HAIKU_ERROR_MAPPER
10215694b30SIngo Weinhold
10315694b30SIngo Weinhold#undef strerror
10415694b30SIngo Weinhold#define strerror(errnum)	_haiku_build_strerror(errnum)
10515694b30SIngo Weinhold
10664266621SAxel Dörfler#endif	// BUILDING_HAIKU_ERROR_MAPPER
10715694b30SIngo Weinhold
10855bc3719SIngo Weinhold
10955bc3719SIngo Weinhold// remap file descriptor functions
11055bc3719SIngo Weinholdint		_haiku_build_fchmod(int fd, mode_t mode);
11155bc3719SIngo Weinholdint		_haiku_build_fchmodat(int fd, const char* path, mode_t mode, int flag);
11255bc3719SIngo Weinholdint		_haiku_build_fstat(int fd, struct stat* st);
11355bc3719SIngo Weinholdint		_haiku_build_fstatat(int fd, const char* path, struct stat* st,
11455bc3719SIngo Weinhold			int flag);
11555bc3719SIngo Weinholdint		_haiku_build_mkdirat(int fd, const char* path, mode_t mode);
11655bc3719SIngo Weinholdint		_haiku_build_mkfifoat(int fd, const char* path, mode_t mode);
11755bc3719SIngo Weinholdint		_haiku_build_utimensat(int fd, const char* path,
11855bc3719SIngo Weinhold			const struct timespec times[2], int flag);
11955bc3719SIngo Weinholdint		_haiku_build_futimens(int fd, const struct timespec times[2]);
12055bc3719SIngo Weinholdint		_haiku_build_faccessat(int fd, const char* path, int accessMode,
12155bc3719SIngo Weinhold			int flag);
12255bc3719SIngo Weinholdint		_haiku_build_fchdir(int fd);
12355bc3719SIngo Weinholdint		_haiku_build_close(int fd);
12455bc3719SIngo Weinholdint		_haiku_build_dup(int fd);
12555bc3719SIngo Weinholdint		_haiku_build_dup2(int fd1, int fd2);
12655bc3719SIngo Weinholdint		_haiku_build_linkat(int toFD, const char* toPath, int pathFD,
12755bc3719SIngo Weinhold			const char* path, int flag);
12855bc3719SIngo Weinholdint		_haiku_build_unlinkat(int fd, const char* path, int flag);
12955bc3719SIngo Weinholdssize_t	_haiku_build_readlinkat(int fd, const char* path, char* buffer,
13055bc3719SIngo Weinhold			size_t bufferSize);
13155bc3719SIngo Weinholdint		_haiku_build_symlinkat(const char* toPath, int fd,
13255bc3719SIngo Weinhold			const char* symlinkPath);
13355bc3719SIngo Weinholdint		_haiku_build_ftruncate(int fd, off_t newSize);
13455bc3719SIngo Weinholdint		_haiku_build_fchown(int fd, uid_t owner, gid_t group);
13555bc3719SIngo Weinholdint		_haiku_build_fchownat(int fd, const char* path, uid_t owner,
13655bc3719SIngo Weinhold			gid_t group, int flag);
13755bc3719SIngo Weinholdint		_haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev);
13855bc3719SIngo Weinholdint		_haiku_build_creat(const char* path, mode_t mode);
13955bc3719SIngo Weinhold#ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
14055bc3719SIngo Weinholdint		_haiku_build_open(const char* path, int openMode, ...);
14155bc3719SIngo Weinholdint		_haiku_build_openat(int fd, const char* path, int openMode, ...);
14255bc3719SIngo Weinholdint		_haiku_build_fcntl(int fd, int op, ...);
14355bc3719SIngo Weinhold#else
14455bc3719SIngo Weinholdint		_haiku_build_open(const char* path, int openMode, mode_t permissions);
14555bc3719SIngo Weinholdint		_haiku_build_openat(int fd, const char* path, int openMode,
14655bc3719SIngo Weinhold			mode_t permissions);
14755bc3719SIngo Weinholdint		_haiku_build_fcntl(int fd, int op, int argument);
14855bc3719SIngo Weinhold#endif
14955bc3719SIngo Weinholdint		_haiku_build_renameat(int fromFD, const char* from, int toFD,
15055bc3719SIngo Weinhold			const char* to);
15155bc3719SIngo Weinhold
15255bc3719SIngo Weinhold#ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
15355bc3719SIngo Weinhold#	define fchmod(fd, mode)				_haiku_build_fchmod(fd, mode)
15455bc3719SIngo Weinhold#	define fchmodat(fd, path, mode, flag) \
15555bc3719SIngo Weinhold		_haiku_build_fchmodat(fd, path, mode, flag)
15655bc3719SIngo Weinhold#	define fstat(fd, st)				_haiku_build_fstat(fd, st)
15755bc3719SIngo Weinhold#	define fstatat(fd, path, st, flag)	_haiku_build_fstatat(fd, path, st, flag)
15855bc3719SIngo Weinhold#	define mkdirat(fd, path, mode)		_haiku_build_mkdirat(fd, path, mode)
15955bc3719SIngo Weinhold#	define mkfifoat(fd, path, mode)		_haiku_build_mkfifoat(fd, path, mode)
16055bc3719SIngo Weinhold#	define utimensat(fd, path, times, flag) \
16155bc3719SIngo Weinhold		_haiku_build_utimensat(fd, path, times, flag)
16255bc3719SIngo Weinhold#	define futimens(fd, times)			_haiku_build_futimens(fd, times)
16355bc3719SIngo Weinhold#	define faccessat(fd, path, accessMode, flag) \
16455bc3719SIngo Weinhold		_haiku_build_faccessat(fd, path, accessMode, flag)
16555bc3719SIngo Weinhold#	define fchdir(fd)					_haiku_build_fchdir(fd)
16655bc3719SIngo Weinhold#	define close(fd)					_haiku_build_close(fd)
16755bc3719SIngo Weinhold#	define dup(fd)						_haiku_build_dup(fd)
16855bc3719SIngo Weinhold#	define dup2(fd1, fd2)				_haiku_build_dup2(fd1, fd2)
16955bc3719SIngo Weinhold#	define linkat(toFD, toPath, pathFD, path, flag) \
17055bc3719SIngo Weinhold		_haiku_build_linkat(toFD, toPath, pathFD, path, flag)
17155bc3719SIngo Weinhold#	define unlinkat(fd, path, flag)		_haiku_build_unlinkat(fd, path, flag)
17255bc3719SIngo Weinhold#	define readlinkat(fd, path, buffer, bufferSize) \
17355bc3719SIngo Weinhold		_haiku_build_readlinkat(fd, path, buffer, bufferSize)
17455bc3719SIngo Weinhold#	define symlinkat(toPath, fd, symlinkPath) \
17555bc3719SIngo Weinhold		_haiku_build_symlinkat(toPath, fd, symlinkPath)
17655bc3719SIngo Weinhold#	define ftruncate(fd, newSize)		_haiku_build_ftruncate(fd, newSize)
17755bc3719SIngo Weinhold#	define fchown(fd, owner, group)		_haiku_build_fchown(fd, owner, group)
17855bc3719SIngo Weinhold#	define fchownat(fd, path, owner, group, flag) \
17955bc3719SIngo Weinhold		_haiku_build_fchownat(fd, path, owner, group, flag)
18055bc3719SIngo Weinhold#	define mknodat(fd, name, mode, dev) \
18155bc3719SIngo Weinhold		_haiku_build_mknodat(fd, name, mode, dev)
18255bc3719SIngo Weinhold#	define creat(path, mode)			_haiku_build_creat(path, mode)
18355bc3719SIngo Weinhold#	define open(path, openMode...)		_haiku_build_open(path, openMode)
18455bc3719SIngo Weinhold#	define openat(fd, path, openMode...) \
18555bc3719SIngo Weinhold		_haiku_build_openat(fd, path, openMode)
18655bc3719SIngo Weinhold#	define fcntl(fd, op...)				_haiku_build_fcntl(fd, op)
18755bc3719SIngo Weinhold#	define renameat(fromFD, from, toFD, to) \
18855bc3719SIngo Weinhold		_haiku_build_renameat(fromFD, from, toFD, to)
189648f0d5fSAugustin Cavalier
190648f0d5fSAugustin Cavalier#	if defined(HAIKU_HOST_USE_XATTR) && defined(HAIKU_HOST_PLATFORM_HAIKU)
191648f0d5fSAugustin Cavalier#		define fs_read_attr			_haiku_build_fs_read_attr
192648f0d5fSAugustin Cavalier#		define fs_write_attr		_haiku_build_fs_write_attr
193648f0d5fSAugustin Cavalier#		define fs_remove_attr		_haiku_build_fs_remove_attr
194648f0d5fSAugustin Cavalier#		define fs_stat_attr			_haiku_build_fs_stat_attr
195648f0d5fSAugustin Cavalier#		define fs_open_attr			_haiku_build_fs_open_attr
196648f0d5fSAugustin Cavalier#		define fs_fopen_attr		_haiku_build_fs_fopen_attr
197648f0d5fSAugustin Cavalier#		define fs_close_attr		_haiku_build_fs_close_attr
198648f0d5fSAugustin Cavalier#		define fs_open_attr_dir		_haiku_build_fs_open_attr_dir
199648f0d5fSAugustin Cavalier#		define fs_fopen_attr_dir	_haiku_build_fs_fopen_attr_dir
200648f0d5fSAugustin Cavalier#		define fs_close_attr_dir	_haiku_build_fs_close_attr_dir
201648f0d5fSAugustin Cavalier#		define fs_read_attr_dir		_haiku_build_fs_read_attr_dir
202648f0d5fSAugustin Cavalier#		define fs_rewind_attr_dir	_haiku_build_fs_rewind_attr_dir
203648f0d5fSAugustin Cavalier#	endif
204648f0d5fSAugustin Cavalier
20555bc3719SIngo Weinhold#endif	// _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
20655bc3719SIngo Weinhold
20755bc3719SIngo Weinhold
20815694b30SIngo Weinhold#ifdef __cplusplus
20915694b30SIngo Weinhold} // extern "C"
21015694b30SIngo Weinhold#endif
21115694b30SIngo Weinhold
21264c51217SIngo Weinhold#endif	// BEOS_BUILD_COMPATIBILITY_H
21315694b30SIngo Weinhold
214