1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
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
16 * Gnomes, ROck Monsters And Chili Sauce
23 /***************************************************************************
25 *cr (C) Copyright 1995-2009 The Board of Trustees of the
26 *cr University of Illinois
27 *cr All Rights Reserved
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 /***************************************************************************
64 * $RCSfile: vmddlopen.c,v $
65 * $Author: johns $ $Locker: $ $State: Exp $
66 * $Revision: 1.18 $ $Date: 2009/07/07 02:40:05 $
68 ***************************************************************************
70 * Routines for loading dynamic link libraries and shared object files
71 * on various platforms, abstracting from machine dependent APIs.
73 ***************************************************************************/
78 #include "vmddlopen.h"
92 void *vmddlopen( const char *path
) {
94 ret
= shl_load( path
, BIND_IMMEDIATE
| BIND_FIRST
| BIND_VERBOSE
, 0);
98 int vmddlclose( void *handle
) {
99 return shl_unload( (shl_t
) handle
);
102 void *vmddlsym( void *handle
, const char *sym
) {
105 if ( shl_findsym( (shl_t
*)&handle
, sym
, TYPE_UNDEFINED
, &value
) != 0 )
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
;
125 retval
= NSCreateObjectFileImageFromFile(path
, &image
);
126 if (retval
!= NSObjectFileImageSuccess
)
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
);
141 void *vmddlsym( void *handle
, const char *symname
) {
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
);
153 return (void *)(NSAddressOfSymbol(sym
));
157 const char *vmddlerror( void ) {
160 const char *fileName
;
161 const char *errorString
= NULL
;
162 NSLinkEditError(&c
, &errorNumber
, &fileName
, &errorString
);
166 #elif defined(_MSC_VER)
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
);
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
);
193 /* All remaining platforms (not Windows, HP-UX, or MacOS X <= 10.3) */
196 void *vmddlopen(const char *fname
) {
197 return dlopen(fname
, RTLD_NOW
);
199 const char *vmddlerror(void) {
202 void *vmddlsym(void *h
, const char *sym
) {
203 return dlsym(h
, sym
);
205 int vmddlclose(void *h
) {
210 void *vmddlopen(const char *fname
) {
213 const char *vmddlerror(void) {
216 void *vmddlsym(void *h
, const char *sym
) {
219 int vmddlclose(void *h
) {