freebsd-nq/lib/libc/gen/dlfunc.c
Garrett Wollman fda2301943 Since POSIX gives us plenary authority to define _t types, change
__dlfunc_t to dlfunc_t to match what I have proposed to the Austin
Group.  (This also makes it easier for applications to store these
values before they decide what to do with them, e.g., in a wrapper
function.)
2002-05-29 19:35:13 +00:00

31 lines
757 B
C

/*
* This source file is in the public domain.
* Garrett A. Wollman, 2002-05-28.
*
* $FreeBSD$
*/
#include <dlfcn.h>
/*
* Implement the dlfunc() interface, which behaves exactly the same as
* dlsym() except that it returns a function pointer instead of a data
* pointer. This can be used by applications to avoid compiler warnings
* about undefined behavior, and is intended as prior art for future
* POSIX standardization. This function requires that all pointer types
* have the same representation, which is true on all platforms FreeBSD
* runs on, but is not guaranteed by the C standard.
*/
dlfunc_t
dlfunc(void *handle, const char *symbol)
{
union {
void *d;
dlfunc_t f;
} rv;
rv.d = dlsym(handle, symbol);
return (rv.f);
}