Fixed typos in GB inner dielectric commit for some kernels.
[gromacs.git] / src / gmxlib / vmddlopen.c
blobe4e6c023e6c68e2de66f77ff6c756e17841ce4e6
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
3 *
4 * This file is part of Gromacs Copyright (c) 1991-2008
5 * David van der Spoel, Erik Lindahl, Berk Hess, University of Groningen.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * To help us fund GROMACS development, we humbly ask that you cite
13 * the research papers on the package. Check out http://www.gromacs.org
15 * And Hey:
16 * Gnomes, ROck Monsters And Chili Sauce
20 /***************************************************************************
21 *cr
22 *cr (C) Copyright 1995-2009 The Board of Trustees of the
23 *cr University of Illinois
24 *cr All Rights Reserved
25 *cr
26 Developed by: Theoretical and Computational Biophysics Group
27 University of Illinois at Urbana-Champaign
28 http://www.ks.uiuc.edu/
30 Permission is hereby granted, free of charge, to any person obtaining a copy of
31 this software and associated documentation files (the Software), to deal with
32 the Software without restriction, including without limitation the rights to
33 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
34 of the Software, and to permit persons to whom the Software is furnished to
35 do so, subject to the following conditions:
37 Redistributions of source code must retain the above copyright notice,
38 this list of conditions and the following disclaimers.
40 Redistributions in binary form must reproduce the above copyright notice,
41 this list of conditions and the following disclaimers in the documentation
42 and/or other materials provided with the distribution.
44 Neither the names of Theoretical and Computational Biophysics Group,
45 University of Illinois at Urbana-Champaign, nor the names of its contributors
46 may be used to endorse or promote products derived from this Software without
47 specific prior written permission.
49 THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
52 THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
53 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
54 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
55 OTHER DEALINGS WITH THE SOFTWARE.
56 ***************************************************************************/
58 /***************************************************************************
59 * RCS INFORMATION:
61 * $RCSfile: vmddlopen.c,v $
62 * $Author: johns $ $Locker: $ $State: Exp $
63 * $Revision: 1.18 $ $Date: 2009/07/07 02:40:05 $
65 ***************************************************************************
66 * DESCRIPTION:
67 * Routines for loading dynamic link libraries and shared object files
68 * on various platforms, abstracting from machine dependent APIs.
70 ***************************************************************************/
72 #include <stdio.h>
73 #include <stdlib.h>
74 #include <string.h>
75 #include "vmddlopen.h"
77 #ifdef HAVE_CONFIG_H
78 #include <config.h>
79 #endif
82 #ifdef GMX_DLOPEN
83 #if defined(__hpux)
85 #include <dl.h>
86 #include <errno.h>
87 #include <string.h>
89 void *vmddlopen( const char *path) {
90 void *ret;
91 ret = shl_load( path, BIND_IMMEDIATE | BIND_FIRST | BIND_VERBOSE, 0);
92 return ret;
95 int vmddlclose( void *handle ) {
96 return shl_unload( (shl_t) handle );
99 void *vmddlsym( void *handle, const char *sym ) {
100 void *value=0;
102 if ( shl_findsym( (shl_t*)&handle, sym, TYPE_UNDEFINED, &value ) != 0 )
103 return 0;
104 return value;
107 const char *vmddlerror( void ) {
108 return strerror( errno );
111 #elif 0 && defined(__APPLE__)
113 * This is only needed for MacOS X version 10.3 or older
115 #include <mach-o/dyld.h>
117 void *vmddlopen( const char *path) {
118 NSObjectFileImage image;
119 NSObjectFileImageReturnCode retval;
120 NSModule module;
122 retval = NSCreateObjectFileImageFromFile(path, &image);
123 if (retval != NSObjectFileImageSuccess)
124 return NULL;
126 module = NSLinkModule(image, path,
127 NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_PRIVATE
128 | NSLINKMODULE_OPTION_RETURN_ON_ERROR);
129 return module; /* module will be NULL on error */
132 int vmddlclose( void *handle ) {
133 NSModule module = (NSModule *)handle;
134 NSUnLinkModule(module, NSUNLINKMODULE_OPTION_NONE);
135 return 0;
138 void *vmddlsym( void *handle, const char *symname ) {
139 char *realsymname;
140 NSModule module;
141 NSSymbol sym;
142 /* Hack around the leading underscore in the symbol name */
143 realsymname = (char *)malloc(strlen(symname)+2);
144 strcpy(realsymname, "_");
145 strcat(realsymname, symname);
146 module = (NSModule)handle;
147 sym = NSLookupSymbolInModule(module, realsymname);
148 free(realsymname);
149 if (sym)
150 return (void *)(NSAddressOfSymbol(sym));
151 return NULL;
154 const char *vmddlerror( void ) {
155 NSLinkEditErrors c;
156 int errorNumber;
157 const char *fileName;
158 const char *errorString = NULL;
159 NSLinkEditError(&c, &errorNumber, &fileName, &errorString);
160 return errorString;
163 #elif defined(_MSC_VER)
165 #include <windows.h>
167 void *vmddlopen(const char *fname) {
168 return (void *)LoadLibrary(fname);
171 const char *vmddlerror(void) {
172 static CHAR szBuf[80];
173 DWORD dw = GetLastError();
175 sprintf(szBuf, "vmddlopen failed: GetLastError returned %u\n", dw);
176 return szBuf;
179 void *vmddlsym(void *h, const char *sym) {
180 return (void *)GetProcAddress((HINSTANCE)h, sym);
183 int vmddlclose(void *h) {
184 /* FreeLibrary returns nonzero on success */
185 return !FreeLibrary((HINSTANCE)h);
188 #else
190 /* All remaining platforms (not Windows, HP-UX, or MacOS X <= 10.3) */
191 #include <dlfcn.h>
193 void *vmddlopen(const char *fname) {
194 return dlopen(fname, RTLD_NOW);
196 const char *vmddlerror(void) {
197 return dlerror();
199 void *vmddlsym(void *h, const char *sym) {
200 return dlsym(h, sym);
202 int vmddlclose(void *h) {
203 return dlclose(h);
205 #endif
206 #else
207 void *vmddlopen(const char *fname) {
208 return NULL;
210 const char *vmddlerror(void) {
211 return NULL;
213 void *vmddlsym(void *h, const char *sym) {
214 return NULL;
216 int vmddlclose(void *h) {
217 return 0;
219 #endif