lemon-project-template-glpk

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