Revised wording in pdb2gmx.c, hopefully clearer now.
[gromacs/rigid-bodies.git] / src / gmxlib / vmddlopen.c
blobc07ae7e53eceab63361f556b7f258f727239e390
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
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
23 /***************************************************************************
24 *cr
25 *cr (C) Copyright 1995-2009 The Board of Trustees of the
26 *cr University of Illinois
27 *cr All Rights Reserved
28 *cr
29 Developed by: Theoretical and Computational Biophysics Group
30 University of Illinois at Urbana-Champaign
31 http://www.ks.uiuc.edu/
33 Permission is hereby granted, free of charge, to any person obtaining a copy of
34 this software and associated documentation files (the Software), to deal with
35 the Software without restriction, including without limitation the rights to
36 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
37 of the Software, and to permit persons to whom the Software is furnished to
38 do so, subject to the following conditions:
40 Redistributions of source code must retain the above copyright notice,
41 this list of conditions and the following disclaimers.
43 Redistributions in binary form must reproduce the above copyright notice,
44 this list of conditions and the following disclaimers in the documentation
45 and/or other materials provided with the distribution.
47 Neither the names of Theoretical and Computational Biophysics Group,
48 University of Illinois at Urbana-Champaign, nor the names of its contributors
49 may be used to endorse or promote products derived from this Software without
50 specific prior written permission.
52 THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
55 THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
56 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
57 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
58 OTHER DEALINGS WITH THE SOFTWARE.
59 ***************************************************************************/
61 /***************************************************************************
62 * RCS INFORMATION:
64 * $RCSfile: vmddlopen.c,v $
65 * $Author: johns $ $Locker: $ $State: Exp $
66 * $Revision: 1.18 $ $Date: 2009/07/07 02:40:05 $
68 ***************************************************************************
69 * DESCRIPTION:
70 * Routines for loading dynamic link libraries and shared object files
71 * on various platforms, abstracting from machine dependent APIs.
73 ***************************************************************************/
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <string.h>
78 #include "vmddlopen.h"
80 #ifdef HAVE_CONFIG_H
81 #include <config.h>
82 #endif
85 #ifdef GMX_DLOPEN
86 #if defined(__hpux)
88 #include <dl.h>
89 #include <errno.h>
90 #include <string.h>
92 void *vmddlopen( const char *path) {
93 void *ret;
94 ret = shl_load( path, BIND_IMMEDIATE | BIND_FIRST | BIND_VERBOSE, 0);
95 return ret;
98 int vmddlclose( void *handle ) {
99 return shl_unload( (shl_t) handle );
102 void *vmddlsym( void *handle, const char *sym ) {
103 void *value=0;
105 if ( shl_findsym( (shl_t*)&handle, sym, TYPE_UNDEFINED, &value ) != 0 )
106 return 0;
107 return value;
110 const char *vmddlerror( void ) {
111 return strerror( errno );
114 #elif 0 && defined(__APPLE__)
116 * This is only needed for MacOS X version 10.3 or older
118 #include <mach-o/dyld.h>
120 void *vmddlopen( const char *path) {
121 NSObjectFileImage image;
122 NSObjectFileImageReturnCode retval;
123 NSModule module;
125 retval = NSCreateObjectFileImageFromFile(path, &image);
126 if (retval != NSObjectFileImageSuccess)
127 return NULL;
129 module = NSLinkModule(image, path,
130 NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_PRIVATE
131 | NSLINKMODULE_OPTION_RETURN_ON_ERROR);
132 return module; /* module will be NULL on error */
135 int vmddlclose( void *handle ) {
136 NSModule module = (NSModule *)handle;
137 NSUnLinkModule(module, NSUNLINKMODULE_OPTION_NONE);
138 return 0;
141 void *vmddlsym( void *handle, const char *symname ) {
142 char *realsymname;
143 NSModule module;
144 NSSymbol sym;
145 /* Hack around the leading underscore in the symbol name */
146 realsymname = (char *)malloc(strlen(symname)+2);
147 strcpy(realsymname, "_");
148 strcat(realsymname, symname);
149 module = (NSModule)handle;
150 sym = NSLookupSymbolInModule(module, realsymname);
151 free(realsymname);
152 if (sym)
153 return (void *)(NSAddressOfSymbol(sym));
154 return NULL;
157 const char *vmddlerror( void ) {
158 NSLinkEditErrors c;
159 int errorNumber;
160 const char *fileName;
161 const char *errorString = NULL;
162 NSLinkEditError(&c, &errorNumber, &fileName, &errorString);
163 return errorString;
166 #elif defined(_MSC_VER)
168 #include <windows.h>
170 void *vmddlopen(const char *fname) {
171 return (void *)LoadLibrary(fname);
174 const char *vmddlerror(void) {
175 static CHAR szBuf[80];
176 DWORD dw = GetLastError();
178 sprintf(szBuf, "vmddlopen failed: GetLastError returned %u\n", dw);
179 return szBuf;
182 void *vmddlsym(void *h, const char *sym) {
183 return (void *)GetProcAddress((HINSTANCE)h, sym);
186 int vmddlclose(void *h) {
187 /* FreeLibrary returns nonzero on success */
188 return !FreeLibrary((HINSTANCE)h);
191 #else
193 /* All remaining platforms (not Windows, HP-UX, or MacOS X <= 10.3) */
194 #include <dlfcn.h>
196 void *vmddlopen(const char *fname) {
197 return dlopen(fname, RTLD_NOW);
199 const char *vmddlerror(void) {
200 return dlerror();
202 void *vmddlsym(void *h, const char *sym) {
203 return dlsym(h, sym);
205 int vmddlclose(void *h) {
206 return dlclose(h);
208 #endif
209 #else
210 void *vmddlopen(const char *fname) {
211 return NULL;
213 const char *vmddlerror(void) {
214 return NULL;
216 void *vmddlsym(void *h, const char *sym) {
217 return NULL;
219 int vmddlclose(void *h) {
220 return 0;
222 #endif