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 9 #include "remapped_functions.h" 10 11 12 #if __GNUC__ >= 4 13 # define HIDDEN_FUNCTION(function) do {} while (0) 14 # define HIDDEN_FUNCTION_ATTRIBUTE __attribute__((visibility("hidden"))) 15 #else 16 # define HIDDEN_FUNCTION(function) asm volatile(".hidden " #function) 17 # define HIDDEN_FUNCTION_ATTRIBUTE 18 #endif 19 20 21 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 22 fchmod(int fd, mode_t mode) 23 { 24 HIDDEN_FUNCTION(fchmod); 25 26 return _haiku_build_fchmod(fd, mode); 27 } 28 29 30 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 31 fchmodat(int fd, const char* path, mode_t mode, int flag) 32 { 33 HIDDEN_FUNCTION(fchmodat); 34 35 return _haiku_build_fchmodat(fd, path, mode, flag); 36 } 37 38 39 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 40 fstat(int fd, struct stat* st) 41 { 42 HIDDEN_FUNCTION(fstat); 43 44 return _haiku_build_fstat(fd, st); 45 } 46 47 48 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 49 fstatat(int fd, const char* path, struct stat* st, int flag) 50 { 51 HIDDEN_FUNCTION(fstatat); 52 53 return _haiku_build_fstatat(fd, path, st, flag); 54 } 55 56 57 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 58 mkdirat(int fd, const char* path, mode_t mode) 59 { 60 HIDDEN_FUNCTION(mkdirat); 61 62 return _haiku_build_mkdirat(fd, path, mode); 63 } 64 65 66 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 67 mkfifoat(int fd, const char* path, mode_t mode) 68 { 69 HIDDEN_FUNCTION(mkfifoat); 70 71 return _haiku_build_mkfifoat(fd, path, mode); 72 } 73 74 75 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 76 utimensat(int fd, const char* path, const struct timespec times[2], int flag) 77 { 78 HIDDEN_FUNCTION(utimensat); 79 80 return _haiku_build_utimensat(fd, path, times, flag); 81 } 82 83 84 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 85 futimens(int fd, const struct timespec times[2]) 86 { 87 HIDDEN_FUNCTION(futimens); 88 89 return _haiku_build_futimens(fd, times); 90 } 91 92 93 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 94 faccessat(int fd, const char* path, int accessMode, int flag) 95 { 96 HIDDEN_FUNCTION(faccessat); 97 98 return _haiku_build_faccessat(fd, path, accessMode, flag); 99 } 100 101 102 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 103 fchdir(int fd) 104 { 105 HIDDEN_FUNCTION(fchdir); 106 107 return _haiku_build_fchdir(fd); 108 } 109 110 111 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 112 close(int fd) 113 { 114 HIDDEN_FUNCTION(close); 115 116 return _haiku_build_close(fd); 117 } 118 119 120 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 121 dup(int fd) 122 { 123 HIDDEN_FUNCTION(dup); 124 125 return _haiku_build_dup(fd); 126 } 127 128 129 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 130 dup2(int fd1, int fd2) 131 { 132 HIDDEN_FUNCTION(dup2); 133 134 return _haiku_build_dup2(fd1, fd2); 135 } 136 137 138 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 139 linkat(int toFD, const char* toPath, int pathFD, const char* path, int flag) 140 { 141 HIDDEN_FUNCTION(linkat); 142 143 return _haiku_build_linkat(toFD, toPath, pathFD, path, flag); 144 } 145 146 147 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 148 unlinkat(int fd, const char* path, int flag) 149 { 150 HIDDEN_FUNCTION(unlinkat); 151 152 return _haiku_build_unlinkat(fd, path, flag); 153 } 154 155 156 extern "C" ssize_t HIDDEN_FUNCTION_ATTRIBUTE 157 readlinkat(int fd, const char* path, char* buffer, size_t bufferSize) 158 { 159 HIDDEN_FUNCTION(readlinkat); 160 161 return _haiku_build_readlinkat(fd, path, buffer, bufferSize); 162 } 163 164 165 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 166 symlinkat(const char* toPath, int fd, const char* symlinkPath) 167 { 168 HIDDEN_FUNCTION(symlinkat); 169 170 return _haiku_build_symlinkat(toPath, fd, symlinkPath); 171 } 172 173 174 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 175 ftruncate(int fd, off_t newSize) 176 { 177 HIDDEN_FUNCTION(ftruncate); 178 179 return _haiku_build_ftruncate(fd, newSize); 180 } 181 182 183 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 184 fchown(int fd, uid_t owner, gid_t group) 185 { 186 HIDDEN_FUNCTION(fchown); 187 188 return _haiku_build_fchown(fd, owner, group); 189 } 190 191 192 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 193 fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag) 194 { 195 HIDDEN_FUNCTION(fchownat); 196 197 return _haiku_build_fchownat(fd, path, owner, group, flag); 198 } 199 200 201 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 202 mknodat(int fd, const char* name, mode_t mode, dev_t dev) 203 { 204 HIDDEN_FUNCTION(mknodat); 205 206 return _haiku_build_mknodat(fd, name, mode, dev); 207 } 208 209 210 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 211 creat(const char* path, mode_t mode) 212 { 213 HIDDEN_FUNCTION(RESOLVE(creat)); 214 215 return _haiku_build_creat(path, mode); 216 } 217 218 219 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 220 open(const char* path, int openMode, ...) 221 { 222 HIDDEN_FUNCTION(open); 223 224 mode_t permissions = 0; 225 if ((openMode & O_CREAT) != 0) { 226 va_list args; 227 va_start(args, openMode); 228 mode_t mask = umask(0); 229 umask(mask); 230 permissions = va_arg(args, int); 231 va_end(args); 232 } 233 234 return _haiku_build_open(path, openMode, permissions); 235 } 236 237 238 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 239 openat(int fd, const char* path, int openMode, ...) 240 { 241 HIDDEN_FUNCTION(openat); 242 243 mode_t permissions = 0; 244 if ((openMode & O_CREAT) != 0) { 245 va_list args; 246 va_start(args, openMode); 247 mode_t mask = umask(0); 248 umask(mask); 249 permissions = va_arg(args, int); 250 va_end(args); 251 } 252 253 return _haiku_build_openat(fd, path, openMode, permissions); 254 } 255 256 257 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 258 fcntl(int fd, int op, ...) 259 { 260 HIDDEN_FUNCTION(fcntl); 261 262 va_list args; 263 va_start(args, op); 264 int argument = va_arg(args, int); 265 va_end(args); 266 267 return _haiku_build_fcntl(fd, op, argument); 268 } 269 270 271 extern "C" int HIDDEN_FUNCTION_ATTRIBUTE 272 renameat(int fromFD, const char* from, int toFD, const char* to) 273 { 274 HIDDEN_FUNCTION(renameat); 275 276 return _haiku_build_renameat(fromFD, from, toFD, to); 277 } 278