*** empty log message ***
[bpt/guile.git] / libguile / dynl-dl.c
CommitLineData
1edae076
MV
1/* dynl-dl.c - dynamic linking for dlopen/dlsym
2 *
7dc6e754 3 * Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
1edae076
MV
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
82892bed
JB
17 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA
1edae076
MV
19 *
20 * As a special exception, the Free Software Foundation gives permission
21 * for additional uses of the text contained in its release of GUILE.
22 *
23 * The exception is that, if you link the GUILE library with other files
24 * to produce an executable, this does not by itself cause the
25 * resulting executable to be covered by the GNU General Public License.
26 * Your use of that executable is in no way restricted on account of
27 * linking the GUILE library code into it.
28 *
29 * This exception does not however invalidate any other reasons why
30 * the executable file might be covered by the GNU General Public License.
31 *
32 * This exception applies only to the code released by the
33 * Free Software Foundation under the name GUILE. If you copy
34 * code from other Free Software Foundation releases into a copy of
35 * GUILE, as the General Public License permits, the exception does
36 * not apply to the code that you add in this way. To avoid misleading
37 * anyone as to the status of such modified files, you must delete
38 * this exception notice from them.
39 *
40 * If you write modifications of your own for GUILE, it is your choice
41 * whether to permit this exception to apply to your modifications.
82892bed 42 * If you do not wish that, delete this exception notice. */
1edae076
MV
43
44/* "dynl.c" dynamically link&load object files.
45 Author: Aubrey Jaffer
46 Modified for libguile by Marius Vollmer */
47
1edae076
MV
48#include <dlfcn.h>
49
1edae076
MV
50#ifdef RTLD_LAZY /* Solaris 2. */
51# define DLOPEN_MODE RTLD_LAZY
52#else
53# define DLOPEN_MODE 1 /* Thats what it says in the man page. */
54#endif
55
7671d04a
MD
56#ifndef RTLD_GLOBAL /* Some systems have no such flag. */
57# define RTLD_GLOBAL 0
58#endif
59
80bc7890 60static void *
56a19408 61sysdep_dynl_link (fname, flags, subr)
3eeba8d4 62 const char *fname;
56a19408 63 int flags;
3eeba8d4 64 const char *subr;
1edae076 65{
56a19408 66 void *handle = dlopen (fname, (DLOPEN_MODE
af1f9aa2 67 | ((flags & DYNL_GLOBAL)? RTLD_GLOBAL : 0)));
80bc7890 68 if (NULL == handle)
419e9e11
MV
69 {
70 SCM_ALLOW_INTS;
80bc7890 71 scm_misc_error (subr, (char *)dlerror (), SCM_EOL);
419e9e11 72 }
80bc7890 73 return handle;
1edae076
MV
74}
75
80bc7890
MV
76static void
77sysdep_dynl_unlink (handle, subr)
78 void *handle;
3eeba8d4 79 const char *subr;
1edae076 80{
419e9e11
MV
81 if (dlclose (handle))
82 {
83 SCM_ALLOW_INTS;
80bc7890 84 scm_misc_error (subr, (char *)dlerror (), SCM_EOL);
419e9e11 85 }
1edae076 86}
80bc7890 87
1edae076 88static void *
80bc7890 89sysdep_dynl_func (symb, handle, subr)
3eeba8d4 90 const char *symb;
1edae076 91 void *handle;
3eeba8d4 92 const char *subr;
1edae076
MV
93{
94 void *fptr;
95 char *err;
cda139a7 96#if defined(USCORE) && !defined(DLSYM_ADDS_USCORE)
2a0d7176 97 char *usymb;
cda139a7 98#endif
1edae076 99
e085f7a6 100#if defined(USCORE) && !defined(DLSYM_ADDS_USCORE)
0113293e 101 usymb = (char *) malloc (strlen (symb) + 2);
2a0d7176
TP
102 *usymb = '_';
103 strcpy (usymb + 1, symb);
0113293e
TP
104 fptr = dlsym (handle, usymb);
105 free (usymb);
e085f7a6
TP
106#else
107 fptr = dlsym (handle, symb);
2a0d7176
TP
108#endif
109
1edae076
MV
110 err = (char *)dlerror ();
111 if (!fptr)
419e9e11
MV
112 {
113 SCM_ALLOW_INTS;
1edae076 114 scm_misc_error (subr, err? err : "symbol has NULL address", SCM_EOL);
419e9e11 115 }
1edae076
MV
116 return fptr;
117}
118
80bc7890
MV
119static void
120sysdep_dynl_init ()
1edae076 121{
1edae076 122}