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