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