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 // DEFFILEMODE is not available on Cygwin, SunOS and when building with musl c 11 #if defined(HAIKU_HOST_PLATFORM_CYGWIN) || defined(HAIKU_HOST_PLATFORM_SUNOS) \ 12 || !defined(DEFFILEMODE) 13 #ifndef DEFFILEMODE 14 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 15 #endif 16 17 // There's no ALLPERMS when building with musl c 18 #ifndef ALLPERMS 19 # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) 20 #endif 21 22 #ifndef S_IUMSK 23 #define S_IUMSK 07777 24 #endif 25 26 #include <ctype.h> 27 #endif 28 29 #ifdef HAIKU_HOST_PLATFORM_SUNOS 30 # include <limits.h> 31 # ifndef NAME_MAX 32 # define NAME_MAX MAXNAMELEN 33 # endif 34 #endif 35 36 typedef unsigned long haiku_build_addr_t; 37 #define addr_t haiku_build_addr_t 38 39 #include <Errors.h> 40 41 #include <fcntl.h> 42 #include <stdio.h> 43 #include <string.h> 44 #include <sys/stat.h> 45 #include <sys/types.h> 46 #include <sys/uio.h> 47 #include <unistd.h> 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 // Is kernel-only under Linux. 54 #ifndef strlcpy 55 extern size_t strlcpy(char* dest, const char* source, size_t length); 56 #endif 57 #ifndef strlcat 58 extern 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) 62 extern size_t strnlen(const char* string, size_t length); 63 #endif 64 65 #if defined(HAIKU_HOST_PLATFORM_CYGWIN) || defined(HAIKU_HOST_PLATFORM_SUNOS) 66 extern char* stpcpy(char* dest, const char* src); 67 extern char* strcasestr(const char* s, const char* find); 68 #endif 69 70 // BeOS only 71 extern ssize_t read_pos(int fd, off_t pos, void* buffer, size_t count); 72 extern ssize_t write_pos(int fd, off_t pos, const void* buffer, size_t count); 73 extern ssize_t readv_pos(int fd, off_t pos, const struct iovec* vec, 74 size_t count); 75 extern 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() 99 extern 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 110 int _haiku_build_fchmod(int fd, mode_t mode); 111 int _haiku_build_fchmodat(int fd, const char* path, mode_t mode, int flag); 112 int _haiku_build_fstat(int fd, struct stat* st); 113 int _haiku_build_fstatat(int fd, const char* path, struct stat* st, 114 int flag); 115 int _haiku_build_mkdirat(int fd, const char* path, mode_t mode); 116 int _haiku_build_mkfifoat(int fd, const char* path, mode_t mode); 117 int _haiku_build_utimensat(int fd, const char* path, 118 const struct timespec times[2], int flag); 119 int _haiku_build_futimens(int fd, const struct timespec times[2]); 120 int _haiku_build_faccessat(int fd, const char* path, int accessMode, 121 int flag); 122 int _haiku_build_fchdir(int fd); 123 int _haiku_build_close(int fd); 124 int _haiku_build_dup(int fd); 125 int _haiku_build_dup2(int fd1, int fd2); 126 int _haiku_build_linkat(int toFD, const char* toPath, int pathFD, 127 const char* path, int flag); 128 int _haiku_build_unlinkat(int fd, const char* path, int flag); 129 ssize_t _haiku_build_readlinkat(int fd, const char* path, char* buffer, 130 size_t bufferSize); 131 int _haiku_build_symlinkat(const char* toPath, int fd, 132 const char* symlinkPath); 133 int _haiku_build_ftruncate(int fd, off_t newSize); 134 int _haiku_build_fchown(int fd, uid_t owner, gid_t group); 135 int _haiku_build_fchownat(int fd, const char* path, uid_t owner, 136 gid_t group, int flag); 137 int _haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev); 138 int _haiku_build_creat(const char* path, mode_t mode); 139 #ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS 140 int _haiku_build_open(const char* path, int openMode, ...); 141 int _haiku_build_openat(int fd, const char* path, int openMode, ...); 142 int _haiku_build_fcntl(int fd, int op, ...); 143 #else 144 int _haiku_build_open(const char* path, int openMode, mode_t permissions); 145 int _haiku_build_openat(int fd, const char* path, int openMode, 146 mode_t permissions); 147 int _haiku_build_fcntl(int fd, int op, int argument); 148 #endif 149 int _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