]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libc/gen/dlfunc.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / lib / libc / gen / dlfunc.c
1 /*
2  * This source file is in the public domain.
3  * Garrett A. Wollman, 2002-05-28.
4  *
5  * $FreeBSD$
6  */
7
8 #include <dlfcn.h>
9
10 /*
11  * Implement the dlfunc() interface, which behaves exactly the same as
12  * dlsym() except that it returns a function pointer instead of a data
13  * pointer.  This can be used by applications to avoid compiler warnings
14  * about undefined behavior, and is intended as prior art for future
15  * POSIX standardization.  This function requires that all pointer types
16  * have the same representation, which is true on all platforms FreeBSD
17  * runs on, but is not guaranteed by the C standard.
18  */
19 dlfunc_t
20 dlfunc(void * __restrict handle, const char * __restrict symbol)
21 {
22         union {
23                 void *d;
24                 dlfunc_t f;
25         } rv;
26
27         rv.d = dlsym(handle, symbol);
28         return (rv.f);
29 }
30