Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly into...
[dragonfly.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: src/lib/libc/gen/dlfunc.c,v 1.3 2002/09/11 05:05:48 mike Exp $
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 }