alpar@1
|
1 |
/* glpenv08.c (shared library support) */
|
alpar@1
|
2 |
|
alpar@1
|
3 |
/***********************************************************************
|
alpar@1
|
4 |
* This code is part of GLPK (GNU Linear Programming Kit).
|
alpar@1
|
5 |
*
|
alpar@1
|
6 |
* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
|
alpar@1
|
7 |
* 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
|
alpar@1
|
8 |
* Moscow Aviation Institute, Moscow, Russia. All rights reserved.
|
alpar@1
|
9 |
* E-mail: <mao@gnu.org>.
|
alpar@1
|
10 |
*
|
alpar@1
|
11 |
* GLPK is free software: you can redistribute it and/or modify it
|
alpar@1
|
12 |
* under the terms of the GNU General Public License as published by
|
alpar@1
|
13 |
* the Free Software Foundation, either version 3 of the License, or
|
alpar@1
|
14 |
* (at your option) any later version.
|
alpar@1
|
15 |
*
|
alpar@1
|
16 |
* GLPK is distributed in the hope that it will be useful, but WITHOUT
|
alpar@1
|
17 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
alpar@1
|
18 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
alpar@1
|
19 |
* License for more details.
|
alpar@1
|
20 |
*
|
alpar@1
|
21 |
* You should have received a copy of the GNU General Public License
|
alpar@1
|
22 |
* along with GLPK. If not, see <http://www.gnu.org/licenses/>.
|
alpar@1
|
23 |
***********************************************************************/
|
alpar@1
|
24 |
|
alpar@1
|
25 |
#ifdef HAVE_CONFIG_H
|
alpar@1
|
26 |
#include <config.h>
|
alpar@1
|
27 |
#endif
|
alpar@1
|
28 |
|
alpar@1
|
29 |
#include "glpenv.h"
|
alpar@1
|
30 |
|
alpar@1
|
31 |
/* GNU version ********************************************************/
|
alpar@1
|
32 |
|
alpar@1
|
33 |
#if defined(HAVE_LTDL)
|
alpar@1
|
34 |
|
alpar@1
|
35 |
#include <ltdl.h>
|
alpar@1
|
36 |
|
alpar@1
|
37 |
void *xdlopen(const char *module)
|
alpar@1
|
38 |
{ void *h = NULL;
|
alpar@1
|
39 |
if (lt_dlinit() != 0)
|
alpar@1
|
40 |
{ lib_err_msg(lt_dlerror());
|
alpar@1
|
41 |
goto done;
|
alpar@1
|
42 |
}
|
alpar@1
|
43 |
h = lt_dlopen(module);
|
alpar@1
|
44 |
if (h == NULL)
|
alpar@1
|
45 |
{ lib_err_msg(lt_dlerror());
|
alpar@1
|
46 |
if (lt_dlexit() != 0)
|
alpar@1
|
47 |
xerror("xdlopen: %s\n", lt_dlerror());
|
alpar@1
|
48 |
}
|
alpar@1
|
49 |
done: return h;
|
alpar@1
|
50 |
}
|
alpar@1
|
51 |
|
alpar@1
|
52 |
void *xdlsym(void *h, const char *symbol)
|
alpar@1
|
53 |
{ void *ptr;
|
alpar@1
|
54 |
xassert(h != NULL);
|
alpar@1
|
55 |
ptr = lt_dlsym(h, symbol);
|
alpar@1
|
56 |
if (ptr == NULL)
|
alpar@1
|
57 |
xerror("xdlsym: %s: %s\n", symbol, lt_dlerror());
|
alpar@1
|
58 |
return ptr;
|
alpar@1
|
59 |
}
|
alpar@1
|
60 |
|
alpar@1
|
61 |
void xdlclose(void *h)
|
alpar@1
|
62 |
{ xassert(h != NULL);
|
alpar@1
|
63 |
if (lt_dlclose(h) != 0)
|
alpar@1
|
64 |
xerror("xdlclose: %s\n", lt_dlerror());
|
alpar@1
|
65 |
if (lt_dlexit() != 0)
|
alpar@1
|
66 |
xerror("xdlclose: %s\n", lt_dlerror());
|
alpar@1
|
67 |
return;
|
alpar@1
|
68 |
}
|
alpar@1
|
69 |
|
alpar@1
|
70 |
/* POSIX version ******************************************************/
|
alpar@1
|
71 |
|
alpar@1
|
72 |
#elif defined(HAVE_DLFCN)
|
alpar@1
|
73 |
|
alpar@1
|
74 |
#include <dlfcn.h>
|
alpar@1
|
75 |
|
alpar@1
|
76 |
void *xdlopen(const char *module)
|
alpar@1
|
77 |
{ void *h;
|
alpar@1
|
78 |
h = dlopen(module, RTLD_NOW);
|
alpar@1
|
79 |
if (h == NULL)
|
alpar@1
|
80 |
lib_err_msg(dlerror());
|
alpar@1
|
81 |
return h;
|
alpar@1
|
82 |
}
|
alpar@1
|
83 |
|
alpar@1
|
84 |
void *xdlsym(void *h, const char *symbol)
|
alpar@1
|
85 |
{ void *ptr;
|
alpar@1
|
86 |
xassert(h != NULL);
|
alpar@1
|
87 |
ptr = dlsym(h, symbol);
|
alpar@1
|
88 |
if (ptr == NULL)
|
alpar@1
|
89 |
xerror("xdlsym: %s: %s\n", symbol, dlerror());
|
alpar@1
|
90 |
return ptr;
|
alpar@1
|
91 |
}
|
alpar@1
|
92 |
|
alpar@1
|
93 |
void xdlclose(void *h)
|
alpar@1
|
94 |
{ xassert(h != NULL);
|
alpar@1
|
95 |
if (dlclose(h) != 0)
|
alpar@1
|
96 |
xerror("xdlclose: %s\n", dlerror());
|
alpar@1
|
97 |
return;
|
alpar@1
|
98 |
}
|
alpar@1
|
99 |
|
alpar@1
|
100 |
/* Windows version ****************************************************/
|
alpar@1
|
101 |
|
alpar@1
|
102 |
#elif defined(__WOE__)
|
alpar@1
|
103 |
|
alpar@1
|
104 |
#include <windows.h>
|
alpar@1
|
105 |
|
alpar@1
|
106 |
void *xdlopen(const char *module)
|
alpar@1
|
107 |
{ void *h;
|
alpar@1
|
108 |
h = LoadLibrary(module);
|
alpar@1
|
109 |
if (h == NULL)
|
alpar@1
|
110 |
{ char msg[20];
|
alpar@1
|
111 |
sprintf(msg, "Error %d", GetLastError());
|
alpar@1
|
112 |
lib_err_msg(msg);
|
alpar@1
|
113 |
}
|
alpar@1
|
114 |
return h;
|
alpar@1
|
115 |
}
|
alpar@1
|
116 |
|
alpar@1
|
117 |
void *xdlsym(void *h, const char *symbol)
|
alpar@1
|
118 |
{ void *ptr;
|
alpar@1
|
119 |
xassert(h != NULL);
|
alpar@1
|
120 |
ptr = GetProcAddress(h, symbol);
|
alpar@1
|
121 |
if (ptr == NULL)
|
alpar@1
|
122 |
xerror("xdlsym: %s: Error %d\n", symbol, GetLastError());
|
alpar@1
|
123 |
return ptr;
|
alpar@1
|
124 |
}
|
alpar@1
|
125 |
|
alpar@1
|
126 |
void xdlclose(void *h)
|
alpar@1
|
127 |
{ xassert(h != NULL);
|
alpar@1
|
128 |
if (!FreeLibrary(h))
|
alpar@1
|
129 |
xerror("xdlclose: Error %d\n", GetLastError());
|
alpar@1
|
130 |
return;
|
alpar@1
|
131 |
}
|
alpar@1
|
132 |
|
alpar@1
|
133 |
/* NULL version *******************************************************/
|
alpar@1
|
134 |
|
alpar@1
|
135 |
#else
|
alpar@1
|
136 |
|
alpar@1
|
137 |
void *xdlopen(const char *module)
|
alpar@1
|
138 |
{ xassert(module == module);
|
alpar@1
|
139 |
lib_err_msg("Shared libraries not supported");
|
alpar@1
|
140 |
return NULL;
|
alpar@1
|
141 |
}
|
alpar@1
|
142 |
|
alpar@1
|
143 |
void *xdlsym(void *h, const char *symbol)
|
alpar@1
|
144 |
{ xassert(h != h);
|
alpar@1
|
145 |
xassert(symbol != symbol);
|
alpar@1
|
146 |
return NULL;
|
alpar@1
|
147 |
}
|
alpar@1
|
148 |
|
alpar@1
|
149 |
void xdlclose(void *h)
|
alpar@1
|
150 |
{ xassert(h != h);
|
alpar@1
|
151 |
return;
|
alpar@1
|
152 |
}
|
alpar@1
|
153 |
|
alpar@1
|
154 |
#endif
|
alpar@1
|
155 |
|
alpar@1
|
156 |
/* eof */
|