xref: /haiku/src/libs/posix_error_mapper/posix_error_mapper.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef POSIX_ERROR_MAPPER_H
6 #define POSIX_ERROR_MAPPER_H
7 
8 #include <dlfcn.h>
9 #include <errno.h>
10 
11 #include <Errors.h>
12 
13 
14 #define GET_REAL_FUNCTION(returnValue, function, parameters)		\
15 	static returnValue (*sReal_##function)parameters				\
16 		= (returnValue (*)parameters)dlsym(RTLD_DEFAULT, #function)
17 
18 #define HIDDEN_FUNCTION(function)	asm volatile(".hidden " #function)
19 
20 #define WRAPPER_FUNCTION(returnValue, function, parameters, body)	\
21 returnValue function parameters										\
22 {																	\
23 	HIDDEN_FUNCTION(function);										\
24 	GET_REAL_FUNCTION(returnValue, function, parameters);			\
25 	body															\
26 }
27 
28 #endif	// POSIX_ERROR_MAPPER_H
29