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