xref: /haiku/headers/build/BeOSBuildCompatibility.h (revision 1b6bc2675fe3691538c8764ab016593f3b06ca53)
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 
29 typedef 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
43 extern "C" {
44 #endif
45 
46 // Is kernel-only under Linux.
47 extern size_t   strlcpy(char* dest, const char* source, size_t length);
48 extern size_t	strlcat(char* dest, const char* source, size_t length);
49 
50 #if defined(HAIKU_HOST_PLATFORM_FREEBSD) || defined(HAIKU_HOST_PLATFORM_DARWIN)
51 extern size_t	strnlen(const char* string, size_t length);
52 #endif
53 
54 #if defined(HAIKU_HOST_PLATFORM_CYGWIN) || defined(HAIKU_HOST_PLATFORM_SUNOS)
55 extern char*	stpcpy(char* dest, const char* src);
56 extern char*	strcasestr(const char* s, const char* find);
57 #endif
58 
59 // BeOS only
60 extern ssize_t  read_pos(int fd, off_t pos, void* buffer, size_t count);
61 extern ssize_t  write_pos(int fd, off_t pos, const void* buffer, size_t count);
62 extern ssize_t	readv_pos(int fd, off_t pos, const struct iovec* vec,
63 					size_t count);
64 extern ssize_t	writev_pos(int fd, off_t pos, const struct iovec* vec,
65 					size_t count);
66 
67 
68 // There's no O_NOTRAVERSE under Linux and FreeBSD -- we replace it with a flag
69 // that won't be used by our tools, preferrably a non-portable one; a fixed
70 // constant could always lead to trouble on the host.
71 // We can abuse this flag for our purposes as we filter it in libroot.
72 #ifndef O_NOTRAVERSE
73 #	ifdef O_NOCTTY
74 #		define O_NOTRAVERSE	O_NOCTTY
75 #	elif defined(O_RANDOM)
76 #		define O_NOTRAVERSE O_RANDOM
77 #	else
78 #		error "Search for a proper replacement value for O_NOTRAVERSE"
79 #	endif
80 #endif
81 
82 #ifndef S_IUMSK
83 #	define S_IUMSK ALLPERMS
84 #endif
85 
86 
87 // remap strerror()
88 extern char* _haiku_build_strerror(int errnum);
89 
90 #ifndef BUILDING_HAIKU_ERROR_MAPPER
91 
92 #undef strerror
93 #define strerror(errnum)	_haiku_build_strerror(errnum)
94 
95 #endif	// BUILDING_HAIKU_ERROR_MAPPER
96 
97 
98 // remap file descriptor functions
99 int		_haiku_build_fchmod(int fd, mode_t mode);
100 int		_haiku_build_fchmodat(int fd, const char* path, mode_t mode, int flag);
101 int		_haiku_build_fstat(int fd, struct stat* st);
102 int		_haiku_build_fstatat(int fd, const char* path, struct stat* st,
103 			int flag);
104 int		_haiku_build_mkdirat(int fd, const char* path, mode_t mode);
105 int		_haiku_build_mkfifoat(int fd, const char* path, mode_t mode);
106 int		_haiku_build_utimensat(int fd, const char* path,
107 			const struct timespec times[2], int flag);
108 int		_haiku_build_futimens(int fd, const struct timespec times[2]);
109 int		_haiku_build_faccessat(int fd, const char* path, int accessMode,
110 			int flag);
111 int		_haiku_build_fchdir(int fd);
112 int		_haiku_build_close(int fd);
113 int		_haiku_build_dup(int fd);
114 int		_haiku_build_dup2(int fd1, int fd2);
115 int		_haiku_build_linkat(int toFD, const char* toPath, int pathFD,
116 			const char* path, int flag);
117 int		_haiku_build_unlinkat(int fd, const char* path, int flag);
118 ssize_t	_haiku_build_readlinkat(int fd, const char* path, char* buffer,
119 			size_t bufferSize);
120 int		_haiku_build_symlinkat(const char* toPath, int fd,
121 			const char* symlinkPath);
122 int		_haiku_build_ftruncate(int fd, off_t newSize);
123 int		_haiku_build_fchown(int fd, uid_t owner, gid_t group);
124 int		_haiku_build_fchownat(int fd, const char* path, uid_t owner,
125 			gid_t group, int flag);
126 int		_haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev);
127 int		_haiku_build_creat(const char* path, mode_t mode);
128 #ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
129 int		_haiku_build_open(const char* path, int openMode, ...);
130 int		_haiku_build_openat(int fd, const char* path, int openMode, ...);
131 int		_haiku_build_fcntl(int fd, int op, ...);
132 #else
133 int		_haiku_build_open(const char* path, int openMode, mode_t permissions);
134 int		_haiku_build_openat(int fd, const char* path, int openMode,
135 			mode_t permissions);
136 int		_haiku_build_fcntl(int fd, int op, int argument);
137 #endif
138 int		_haiku_build_renameat(int fromFD, const char* from, int toFD,
139 			const char* to);
140 
141 #ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
142 #	define fchmod(fd, mode)				_haiku_build_fchmod(fd, mode)
143 #	define fchmodat(fd, path, mode, flag) \
144 		_haiku_build_fchmodat(fd, path, mode, flag)
145 #	define fstat(fd, st)				_haiku_build_fstat(fd, st)
146 #	define fstatat(fd, path, st, flag)	_haiku_build_fstatat(fd, path, st, flag)
147 #	define mkdirat(fd, path, mode)		_haiku_build_mkdirat(fd, path, mode)
148 #	define mkfifoat(fd, path, mode)		_haiku_build_mkfifoat(fd, path, mode)
149 #	define utimensat(fd, path, times, flag) \
150 		_haiku_build_utimensat(fd, path, times, flag)
151 #	define futimens(fd, times)			_haiku_build_futimens(fd, times)
152 #	define faccessat(fd, path, accessMode, flag) \
153 		_haiku_build_faccessat(fd, path, accessMode, flag)
154 #	define fchdir(fd)					_haiku_build_fchdir(fd)
155 #	define close(fd)					_haiku_build_close(fd)
156 #	define dup(fd)						_haiku_build_dup(fd)
157 #	define dup2(fd1, fd2)				_haiku_build_dup2(fd1, fd2)
158 #	define linkat(toFD, toPath, pathFD, path, flag) \
159 		_haiku_build_linkat(toFD, toPath, pathFD, path, flag)
160 #	define unlinkat(fd, path, flag)		_haiku_build_unlinkat(fd, path, flag)
161 #	define readlinkat(fd, path, buffer, bufferSize) \
162 		_haiku_build_readlinkat(fd, path, buffer, bufferSize)
163 #	define symlinkat(toPath, fd, symlinkPath) \
164 		_haiku_build_symlinkat(toPath, fd, symlinkPath)
165 #	define ftruncate(fd, newSize)		_haiku_build_ftruncate(fd, newSize)
166 #	define fchown(fd, owner, group)		_haiku_build_fchown(fd, owner, group)
167 #	define fchownat(fd, path, owner, group, flag) \
168 		_haiku_build_fchownat(fd, path, owner, group, flag)
169 #	define mknodat(fd, name, mode, dev) \
170 		_haiku_build_mknodat(fd, name, mode, dev)
171 #	define creat(path, mode)			_haiku_build_creat(path, mode)
172 #	define open(path, openMode...)		_haiku_build_open(path, openMode)
173 #	define openat(fd, path, openMode...) \
174 		_haiku_build_openat(fd, path, openMode)
175 #	define fcntl(fd, op...)				_haiku_build_fcntl(fd, op)
176 #	define renameat(fromFD, from, toFD, to) \
177 		_haiku_build_renameat(fromFD, from, toFD, to)
178 #endif	// _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
179 
180 
181 #ifdef __cplusplus
182 } // extern "C"
183 #endif
184 
185 #endif	// BEOS_BUILD_COMPATIBILITY_H
186 
187