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
22extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
23fchmod(int fd, mode_t mode)
24{
25	HIDDEN_FUNCTION(fchmod);
26
27	return _haiku_build_fchmod(fd, mode);
28}
29
30
31extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
32fchmodat(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
40extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
41fstat(int fd, struct stat* st)
42{
43	HIDDEN_FUNCTION(fstat);
44
45	return _haiku_build_fstat(fd, st);
46}
47
48
49extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
50fstatat(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
58extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
59mkdirat(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
67extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
68mkfifoat(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
76extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
77utimensat(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
85extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
86futimens(int fd, const struct timespec times[2])
87{
88	HIDDEN_FUNCTION(futimens);
89
90	return _haiku_build_futimens(fd, times);
91}
92
93
94extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
95faccessat(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
103extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
104fchdir(int fd)
105{
106	HIDDEN_FUNCTION(fchdir);
107
108	return _haiku_build_fchdir(fd);
109}
110
111
112extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
113close(int fd)
114{
115	HIDDEN_FUNCTION(close);
116
117	return _haiku_build_close(fd);
118}
119
120
121extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
122dup(int fd)
123{
124	HIDDEN_FUNCTION(dup);
125
126	return _haiku_build_dup(fd);
127}
128
129
130extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
131dup2(int fd1, int fd2)
132{
133	HIDDEN_FUNCTION(dup2);
134
135	return _haiku_build_dup2(fd1, fd2);
136}
137
138
139extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
140linkat(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
148extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
149unlinkat(int fd, const char* path, int flag)
150{
151	HIDDEN_FUNCTION(unlinkat);
152
153	return _haiku_build_unlinkat(fd, path, flag);
154}
155
156
157extern "C" ssize_t HIDDEN_FUNCTION_ATTRIBUTE
158readlinkat(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
166extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
167symlinkat(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
175extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
176ftruncate(int fd, off_t newSize)
177{
178	HIDDEN_FUNCTION(ftruncate);
179
180	return _haiku_build_ftruncate(fd, newSize);
181}
182
183
184extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
185fchown(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
193extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
194fchownat(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
202extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
203mknodat(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
211extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
212creat(const char* path, mode_t mode)
213{
214	HIDDEN_FUNCTION(creat);
215
216	return _haiku_build_creat(path, mode);
217}
218
219
220extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
221open(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
239extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
240openat(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
258extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
259fcntl(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
272extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
273renameat(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
285extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE
286fs_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
294extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE
295fs_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
303extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE
304fs_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
312extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
313fs_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
321extern "C" addr_t HIDDEN_FUNCTION_ATTRIBUTE
322fs_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
330extern "C" void HIDDEN_FUNCTION_ATTRIBUTE
331fs_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
339extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
340fs_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
348extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
349fs_close_attr(int fd)
350{
351	HIDDEN_FUNCTION(fs_close_attr);
352
353	return _haiku_build_fs_close_attr(fd);
354}
355
356
357extern "C" ssize_t HIDDEN_FUNCTION_ATTRIBUTE
358fs_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
368extern "C" ssize_t HIDDEN_FUNCTION_ATTRIBUTE
369fs_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
379extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
380fs_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
388extern "C" int HIDDEN_FUNCTION_ATTRIBUTE
389fs_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