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