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