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