1 /* 2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <stdarg.h> 8 #include <fcntl.h> 9 10 #include "remapped_functions.h" 11 12 13 #if __GNUC__ >= 4 14 # define HIDDEN_FUNCTION(function) do {} while (0) 15 # define HIDDEN_FUNCTION_ATTRIBUTE __attribute__((visibility("hidden"))) 16 #else 17 # define HIDDEN_FUNCTION(function) asm volatile(".hidden " #function) 18 # define HIDDEN_FUNCTION_ATTRIBUTE 19 #endif 20 21 22 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 23 fchmod(int fd, mode_t mode) 24 { 25 HIDDEN_FUNCTION(fchmod); 26 27 return _haiku_build_fchmod(fd, mode); 28 } 29 30 31 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 32 fchmodat(int fd, const char* path, mode_t mode, int flag) 33 { 34 HIDDEN_FUNCTION(fchmodat); 35 36 return _haiku_build_fchmodat(fd, path, mode, flag); 37 } 38 39 40 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 41 fstat(int fd, struct stat* st) 42 { 43 HIDDEN_FUNCTION(fstat); 44 45 return _haiku_build_fstat(fd, st); 46 } 47 48 49 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 50 fstatat(int fd, const char* path, struct stat* st, int flag) 51 { 52 HIDDEN_FUNCTION(fstatat); 53 54 return _haiku_build_fstatat(fd, path, st, flag); 55 } 56 57 58 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 59 mkdirat(int fd, const char* path, mode_t mode) 60 { 61 HIDDEN_FUNCTION(mkdirat); 62 63 return _haiku_build_mkdirat(fd, path, mode); 64 } 65 66 67 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 68 mkfifoat(int fd, const char* path, mode_t mode) 69 { 70 HIDDEN_FUNCTION(mkfifoat); 71 72 return _haiku_build_mkfifoat(fd, path, mode); 73 } 74 75 76 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 77 utimensat(int fd, const char* path, const struct timespec times[2], int flag) 78 { 79 HIDDEN_FUNCTION(utimensat); 80 81 return _haiku_build_utimensat(fd, path, times, flag); 82 } 83 84 85 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 86 futimens(int fd, const struct timespec times[2]) 87 { 88 HIDDEN_FUNCTION(futimens); 89 90 return _haiku_build_futimens(fd, times); 91 } 92 93 94 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 95 faccessat(int fd, const char* path, int accessMode, int flag) 96 { 97 HIDDEN_FUNCTION(faccessat); 98 99 return _haiku_build_faccessat(fd, path, accessMode, flag); 100 } 101 102 103 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 104 fchdir(int fd) 105 { 106 HIDDEN_FUNCTION(fchdir); 107 108 return _haiku_build_fchdir(fd); 109 } 110 111 112 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 113 close(int fd) 114 { 115 HIDDEN_FUNCTION(close); 116 117 return _haiku_build_close(fd); 118 } 119 120 121 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 122 dup(int fd) 123 { 124 HIDDEN_FUNCTION(dup); 125 126 return _haiku_build_dup(fd); 127 } 128 129 130 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 131 dup2(int fd1, int fd2) 132 { 133 HIDDEN_FUNCTION(dup2); 134 135 return _haiku_build_dup2(fd1, fd2); 136 } 137 138 139 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 140 linkat(int toFD, const char* toPath, int pathFD, const char* path, int flag) 141 { 142 HIDDEN_FUNCTION(linkat); 143 144 return _haiku_build_linkat(toFD, toPath, pathFD, path, flag); 145 } 146 147 148 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 149 unlinkat(int fd, const char* path, int flag) 150 { 151 HIDDEN_FUNCTION(unlinkat); 152 153 return _haiku_build_unlinkat(fd, path, flag); 154 } 155 156 157 extern "C" ssize_t HIDDEN_FUNCTION_ATTRIBUTE 158 readlinkat(int fd, const char* path, char* buffer, size_t bufferSize) 159 { 160 HIDDEN_FUNCTION(readlinkat); 161 162 return _haiku_build_readlinkat(fd, path, buffer, bufferSize); 163 } 164 165 166 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 167 symlinkat(const char* toPath, int fd, const char* symlinkPath) 168 { 169 HIDDEN_FUNCTION(symlinkat); 170 171 return _haiku_build_symlinkat(toPath, fd, symlinkPath); 172 } 173 174 175 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 176 ftruncate(int fd, off_t newSize) 177 { 178 HIDDEN_FUNCTION(ftruncate); 179 180 return _haiku_build_ftruncate(fd, newSize); 181 } 182 183 184 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 185 fchown(int fd, uid_t owner, gid_t group) 186 { 187 HIDDEN_FUNCTION(fchown); 188 189 return _haiku_build_fchown(fd, owner, group); 190 } 191 192 193 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 194 fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag) 195 { 196 HIDDEN_FUNCTION(fchownat); 197 198 return _haiku_build_fchownat(fd, path, owner, group, flag); 199 } 200 201 202 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 203 mknodat(int fd, const char* name, mode_t mode, dev_t dev) 204 { 205 HIDDEN_FUNCTION(mknodat); 206 207 return _haiku_build_mknodat(fd, name, mode, dev); 208 } 209 210 211 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 212 creat(const char* path, mode_t mode) 213 { 214 HIDDEN_FUNCTION(creat); 215 216 return _haiku_build_creat(path, mode); 217 } 218 219 220 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 221 open(const char* path, int openMode, ...) 222 { 223 HIDDEN_FUNCTION(open); 224 225 mode_t permissions = 0; 226 if ((openMode & O_CREAT) != 0) { 227 va_list args; 228 va_start(args, openMode); 229 mode_t mask = umask(0); 230 umask(mask); 231 permissions = va_arg(args, int); 232 va_end(args); 233 } 234 235 return _haiku_build_open(path, openMode, permissions); 236 } 237 238 239 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 240 openat(int fd, const char* path, int openMode, ...) 241 { 242 HIDDEN_FUNCTION(openat); 243 244 mode_t permissions = 0; 245 if ((openMode & O_CREAT) != 0) { 246 va_list args; 247 va_start(args, openMode); 248 mode_t mask = umask(0); 249 umask(mask); 250 permissions = va_arg(args, int); 251 va_end(args); 252 } 253 254 return _haiku_build_openat(fd, path, openMode, permissions); 255 } 256 257 258 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 259 fcntl(int fd, int op, ...) 260 { 261 HIDDEN_FUNCTION(fcntl); 262 263 va_list args; 264 va_start(args, op); 265 int argument = va_arg(args, int); 266 va_end(args); 267 268 return _haiku_build_fcntl(fd, op, argument); 269 } 270 271 272 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 273 renameat(int fromFD, const char* from, int toFD, const char* to) 274 { 275 HIDDEN_FUNCTION(renameat); 276 277 return _haiku_build_renameat(fromFD, from, toFD, to); 278 } 279 280 281 #if defined(HAIKU_HOST_USE_XATTR) && defined(HAIKU_HOST_PLATFORM_HAIKU) 282 // fs_attr_* functions only need to be remapped on Haiku 283 284 285 extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE 286 fs_open_attr_dir(const char *path) 287 { 288 HIDDEN_FUNCTION(fs_open_attr_dir); 289 290 return (addr_t)_haiku_build_fs_open_attr_dir(path); 291 } 292 293 294 extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE 295 fs_lopen_attr_dir(const char *path) 296 { 297 HIDDEN_FUNCTION(fs_lopen_attr_dir); 298 299 return (addr_t)_haiku_build_fs_lopen_attr_dir(path); 300 } 301 302 303 extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE 304 fs_fopen_attr_dir(int fd) 305 { 306 HIDDEN_FUNCTION(fs_fopen_attr_dir); 307 308 return (addr_t)_haiku_build_fs_fopen_attr_dir(fd); 309 } 310 311 312 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 313 fs_close_attr_dir(void *dir) 314 { 315 HIDDEN_FUNCTION(fs_close_attr_dir); 316 317 return _haiku_build_fs_close_attr_dir(dir); 318 } 319 320 321 extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE 322 fs_read_attr_dir(void *dir) 323 { 324 HIDDEN_FUNCTION(fs_read_attr_dir); 325 326 return (addr_t)_haiku_build_fs_read_attr_dir(dir); 327 } 328 329 330 extern "C" void HIDDEN_FUNCTION_ATTRIBUTE 331 fs_rewind_attr_dir(void *dir) 332 { 333 HIDDEN_FUNCTION(fs_rewind_attr_dir); 334 335 _haiku_build_fs_rewind_attr_dir(dir); 336 } 337 338 339 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 340 fs_fopen_attr(int fd, const char *attribute, uint32 type, int openMode) 341 { 342 HIDDEN_FUNCTION(fs_fopen_attr); 343 344 return _haiku_build_fs_fopen_attr(fd, attribute, type, openMode); 345 } 346 347 348 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 349 fs_close_attr(int fd) 350 { 351 HIDDEN_FUNCTION(fs_close_attr); 352 353 return _haiku_build_fs_close_attr(fd); 354 } 355 356 357 extern "C" ssize_t HIDDEN_FUNCTION_ATTRIBUTE 358 fs_read_attr(int fd, const char* attribute, uint32 type, off_t pos, 359 void *buffer, size_t readBytes) 360 { 361 HIDDEN_FUNCTION(fs_read_attr); 362 363 return _haiku_build_fs_read_attr(fd, attribute, type, pos, buffer, 364 readBytes); 365 } 366 367 368 extern "C" ssize_t HIDDEN_FUNCTION_ATTRIBUTE 369 fs_write_attr(int fd, const char* attribute, uint32 type, off_t pos, 370 const void *buffer, size_t writeBytes) 371 { 372 HIDDEN_FUNCTION(fs_write_attr); 373 374 return _haiku_build_fs_write_attr(fd, attribute, type, pos, buffer, 375 writeBytes); 376 } 377 378 379 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 380 fs_remove_attr(int fd, const char* attribute) 381 { 382 HIDDEN_FUNCTION(fs_remove_attr); 383 384 return _haiku_build_fs_remove_attr(fd, attribute); 385 } 386 387 388 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 389 fs_stat_attr(int fd, const char *attribute, struct attr_info *attrInfo) 390 { 391 HIDDEN_FUNCTION(fs_stat_attr); 392 393 return _haiku_build_fs_stat_attr(fd, attribute, attrInfo); 394 } 395 396 #endif // defined(HAIKU_HOST_USE_XATTR) && defined(HAIKU_HOST_PLATFORM_HAIKU) 397