2 /* --------------------------------------------------------------------------
3 * Dynamic loading (of .dll or .so files) for Hugs
5 * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
6 * Yale Haskell Group, and the Oregon Graduate Institute of Science and
7 * Technology, 1994-1999, All rights reserved. It is distributed as
8 * free software under the license in the file "License", which is
9 * included in the distribution.
11 * $RCSfile: dynamic.c,v $
13 * $Date: 1999/10/29 13:41:23 $
14 * ------------------------------------------------------------------------*/
21 #if HAVE_WINDOWS_H && !defined(__MSDOS__)
25 void* getDLLSymbol(line,dll0,symbol0) /* load dll and lookup symbol */
34 if (strlen(dll0) > 996) {
35 ERRMSG(line) "Excessively long library name:\n%s\n",dll0
41 if (strlen(symbol0) > 96) {
42 ERRMSG(line) "Excessively long symbol name:\n%s\n",symbol0
45 strcpy(&(symbol[1]),symbol0);
48 instance = LoadLibrary(dll);
49 if (NULL == instance) {
50 /* GetLastError allegedly provides more detail - in practice,
51 * it tells you nothing more.
53 ERRMSG(line) "Can't open library \"%s\"", dll
56 sym = GetProcAddress(instance,symbol0);
60 Bool stdcallAllowed ( void )
70 #elif HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
75 void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */
82 if (strlen(dll0) > 996) {
83 ERRMSG(line) "Excessively long library name:\n%s\n",dll0
89 instance = dlopen(dll,RTLD_NOW);
90 #elif defined RTLD_LAZY /* eg SunOS4 doesn't have RTLD_NOW */
91 instance = dlopen(dll,RTLD_LAZY);
92 #else /* eg FreeBSD doesn't have RTLD_LAZY */
93 instance = dlopen(dll,1);
96 if (NULL == instance) {
97 ERRMSG(line) "Can't open library \"%s\":\n %s\n",dll,dlerror()
100 if ((sym = dlsym(instance,symbol)))
103 ERRMSG(line) "Can't find symbol \"%s\" in library \"%s\"",symbol,dll
107 Bool stdcallAllowed ( void )
117 #elif HAVE_DL_H /* eg HPUX */
121 void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */
125 ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L);
127 if (NULL == instance) {
128 ERRMSG(line) "Error while importing DLL \"%s\"", dll0
131 return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;
134 Bool stdcallAllowed ( void )
144 #else /* Dynamic loading not available */
146 void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */
150 #if 1 /* very little to choose between these options */
153 ERRMSG(line) "This Hugs build does not support dynamic loading\n"
158 Bool stdcallAllowed ( void )
163 #endif /* Dynamic loading not available */