src/glpenv08.c
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 06 Dec 2010 13:09:21 +0100
changeset 1 c445c931472f
permissions -rw-r--r--
Import glpk-4.45

- Generated files and doc/notes are removed
     1 /* glpenv08.c (shared library support) */
     2 
     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 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 ***********************************************************************/
    24 
    25 #ifdef HAVE_CONFIG_H
    26 #include <config.h>
    27 #endif
    28 
    29 #include "glpenv.h"
    30 
    31 /* GNU version ********************************************************/
    32 
    33 #if defined(HAVE_LTDL)
    34 
    35 #include <ltdl.h>
    36 
    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 }
    51 
    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 }
    60 
    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 }
    69 
    70 /* POSIX version ******************************************************/
    71 
    72 #elif defined(HAVE_DLFCN)
    73 
    74 #include <dlfcn.h>
    75 
    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 }
    83 
    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 }
    92 
    93 void xdlclose(void *h)
    94 {     xassert(h != NULL);
    95       if (dlclose(h) != 0)
    96          xerror("xdlclose: %s\n", dlerror());
    97       return;
    98 }
    99 
   100 /* Windows version ****************************************************/
   101 
   102 #elif defined(__WOE__)
   103 
   104 #include <windows.h>
   105 
   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 }
   116 
   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 }
   125 
   126 void xdlclose(void *h)
   127 {     xassert(h != NULL);
   128       if (!FreeLibrary(h))
   129          xerror("xdlclose: Error %d\n", GetLastError());
   130       return;
   131 }
   132 
   133 /* NULL version *******************************************************/
   134 
   135 #else
   136 
   137 void *xdlopen(const char *module)
   138 {     xassert(module == module);
   139       lib_err_msg("Shared libraries not supported");
   140       return NULL;
   141 }
   142 
   143 void *xdlsym(void *h, const char *symbol)
   144 {     xassert(h != h);
   145       xassert(symbol != symbol);
   146       return NULL;
   147 }
   148 
   149 void xdlclose(void *h)
   150 {     xassert(h != h);
   151       return;
   152 }
   153 
   154 #endif
   155 
   156 /* eof */