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