xref: /illumos-gate/usr/src/contrib/ast/src/lib/libdll/dlllook.c (revision b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1997-2012 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22  * Glenn Fowler
23  * AT&T Research
24  */
25 
26 #include <ast.h>
27 #include <error.h>
28 #include <dlldefs.h>
29 
30 /*
31  * dlsym() with `_' weak fallback
32  */
33 
34 void*
dlllook(void * dll,const char * name)35 dlllook(void* dll, const char* name)
36 {
37 	register void*	addr;
38 	char		buf[256];
39 
40 	if (!(addr = dlsym(dll, name)) && strlen(name) < (sizeof(buf) - 2))
41 	{
42 		buf[0] = '_';
43 		strcpy(buf + 1, name);
44 		name = (const char*)buf;
45 		addr = dlsym(dll, name);
46 	}
47 	errorf("dll", NiL, -1, "dlllook: %s addr %p", name, addr);
48 	return addr;
49 }
50