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/11/25 10:19:15 $
14 * ------------------------------------------------------------------------*/
22 #if HAVE_WINDOWS_H && !defined(__MSDOS__)
26 void* getDLLSymbol(line,dll0,symbol0) /* load dll and lookup symbol */
35 if (strlen(dll0) > 996-strlen(installDir)) {
36 ERRMSG(line) "Excessively long library name:\n%s\n",dll0
40 if (strcmp("nHandle",dll0)==0) strcat(dll,installDir);
44 if (strlen(symbol0) > 96) {
45 ERRMSG(line) "Excessively long symbol name:\n%s\n",symbol0
48 strcpy(&(symbol[1]),symbol0);
51 instance = LoadLibrary(dll);
52 if (NULL == instance) {
53 /* GetLastError allegedly provides more detail - in practice,
54 * it tells you nothing more.
56 ERRMSG(line) "Can't open library \"%s\"", dll
59 sym = GetProcAddress(instance,symbol0);
63 Bool stdcallAllowed ( void )
73 #elif HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
78 void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */
85 if (strlen(dll0) > 996-strlen(installDir)) {
86 ERRMSG(line) "Excessively long library name:\n%s\n",dll0
90 if (strcmp("nHandle",dll0)==0) strcat(dll,installDir);
94 instance = dlopen(dll,RTLD_NOW);
95 #elif defined RTLD_LAZY /* eg SunOS4 doesn't have RTLD_NOW */
96 instance = dlopen(dll,RTLD_LAZY);
97 #else /* eg FreeBSD doesn't have RTLD_LAZY */
98 instance = dlopen(dll,1);
101 if (NULL == instance) {
102 ERRMSG(line) "Can't open library \"%s\":\n %s\n",dll,dlerror()
105 if ((sym = dlsym(instance,symbol)))
108 ERRMSG(line) "Can't find symbol \"%s\" in library \"%s\"",symbol,dll
112 Bool stdcallAllowed ( void )
122 #elif HAVE_DL_H /* eg HPUX */
126 void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */
130 ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L);
132 if (NULL == instance) {
133 ERRMSG(line) "Error while importing DLL \"%s\"", dll0
136 return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;
139 Bool stdcallAllowed ( void )
149 #else /* Dynamic loading not available */
151 void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */
155 #if 1 /* very little to choose between these options */
158 ERRMSG(line) "This Hugs build does not support dynamic loading\n"
163 Bool stdcallAllowed ( void )
168 #endif /* Dynamic loading not available */