alpar@1: /* glpenv08.c (shared library support) */ alpar@1: alpar@1: /*********************************************************************** alpar@1: * This code is part of GLPK (GNU Linear Programming Kit). alpar@1: * alpar@1: * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: * Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: * E-mail: . alpar@1: * alpar@1: * GLPK is free software: you can redistribute it and/or modify it alpar@1: * under the terms of the GNU General Public License as published by alpar@1: * the Free Software Foundation, either version 3 of the License, or alpar@1: * (at your option) any later version. alpar@1: * alpar@1: * GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: * License for more details. alpar@1: * alpar@1: * You should have received a copy of the GNU General Public License alpar@1: * along with GLPK. If not, see . alpar@1: ***********************************************************************/ alpar@1: alpar@1: #ifdef HAVE_CONFIG_H alpar@1: #include alpar@1: #endif alpar@1: alpar@1: #include "glpenv.h" alpar@1: alpar@1: /* GNU version ********************************************************/ alpar@1: alpar@1: #if defined(HAVE_LTDL) alpar@1: alpar@1: #include alpar@1: alpar@1: void *xdlopen(const char *module) alpar@1: { void *h = NULL; alpar@1: if (lt_dlinit() != 0) alpar@1: { lib_err_msg(lt_dlerror()); alpar@1: goto done; alpar@1: } alpar@1: h = lt_dlopen(module); alpar@1: if (h == NULL) alpar@1: { lib_err_msg(lt_dlerror()); alpar@1: if (lt_dlexit() != 0) alpar@1: xerror("xdlopen: %s\n", lt_dlerror()); alpar@1: } alpar@1: done: return h; alpar@1: } alpar@1: alpar@1: void *xdlsym(void *h, const char *symbol) alpar@1: { void *ptr; alpar@1: xassert(h != NULL); alpar@1: ptr = lt_dlsym(h, symbol); alpar@1: if (ptr == NULL) alpar@1: xerror("xdlsym: %s: %s\n", symbol, lt_dlerror()); alpar@1: return ptr; alpar@1: } alpar@1: alpar@1: void xdlclose(void *h) alpar@1: { xassert(h != NULL); alpar@1: if (lt_dlclose(h) != 0) alpar@1: xerror("xdlclose: %s\n", lt_dlerror()); alpar@1: if (lt_dlexit() != 0) alpar@1: xerror("xdlclose: %s\n", lt_dlerror()); alpar@1: return; alpar@1: } alpar@1: alpar@1: /* POSIX version ******************************************************/ alpar@1: alpar@1: #elif defined(HAVE_DLFCN) alpar@1: alpar@1: #include alpar@1: alpar@1: void *xdlopen(const char *module) alpar@1: { void *h; alpar@1: h = dlopen(module, RTLD_NOW); alpar@1: if (h == NULL) alpar@1: lib_err_msg(dlerror()); alpar@1: return h; alpar@1: } alpar@1: alpar@1: void *xdlsym(void *h, const char *symbol) alpar@1: { void *ptr; alpar@1: xassert(h != NULL); alpar@1: ptr = dlsym(h, symbol); alpar@1: if (ptr == NULL) alpar@1: xerror("xdlsym: %s: %s\n", symbol, dlerror()); alpar@1: return ptr; alpar@1: } alpar@1: alpar@1: void xdlclose(void *h) alpar@1: { xassert(h != NULL); alpar@1: if (dlclose(h) != 0) alpar@1: xerror("xdlclose: %s\n", dlerror()); alpar@1: return; alpar@1: } alpar@1: alpar@1: /* Windows version ****************************************************/ alpar@1: alpar@1: #elif defined(__WOE__) alpar@1: alpar@1: #include alpar@1: alpar@1: void *xdlopen(const char *module) alpar@1: { void *h; alpar@1: h = LoadLibrary(module); alpar@1: if (h == NULL) alpar@1: { char msg[20]; alpar@1: sprintf(msg, "Error %d", GetLastError()); alpar@1: lib_err_msg(msg); alpar@1: } alpar@1: return h; alpar@1: } alpar@1: alpar@1: void *xdlsym(void *h, const char *symbol) alpar@1: { void *ptr; alpar@1: xassert(h != NULL); alpar@1: ptr = GetProcAddress(h, symbol); alpar@1: if (ptr == NULL) alpar@1: xerror("xdlsym: %s: Error %d\n", symbol, GetLastError()); alpar@1: return ptr; alpar@1: } alpar@1: alpar@1: void xdlclose(void *h) alpar@1: { xassert(h != NULL); alpar@1: if (!FreeLibrary(h)) alpar@1: xerror("xdlclose: Error %d\n", GetLastError()); alpar@1: return; alpar@1: } alpar@1: alpar@1: /* NULL version *******************************************************/ alpar@1: alpar@1: #else alpar@1: alpar@1: void *xdlopen(const char *module) alpar@1: { xassert(module == module); alpar@1: lib_err_msg("Shared libraries not supported"); alpar@1: return NULL; alpar@1: } alpar@1: alpar@1: void *xdlsym(void *h, const char *symbol) alpar@1: { xassert(h != h); alpar@1: xassert(symbol != symbol); alpar@1: return NULL; alpar@1: } alpar@1: alpar@1: void xdlclose(void *h) alpar@1: { xassert(h != h); alpar@1: return; alpar@1: } alpar@1: alpar@1: #endif alpar@1: alpar@1: /* eof */