* configure.in: Only define DYNAMIC_LINKING when one of the system
[bpt/guile.git] / libguile / dynl.c
CommitLineData
1edae076
MV
1/* dynl.c - dynamic linking
2 *
3 * Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
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
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * As a special exception, the Free Software Foundation gives permission
20 * for additional uses of the text contained in its release of GUILE.
21 *
22 * The exception is that, if you link the GUILE library with other files
23 * to produce an executable, this does not by itself cause the
24 * resulting executable to be covered by the GNU General Public License.
25 * Your use of that executable is in no way restricted on account of
26 * linking the GUILE library code into it.
27 *
28 * This exception does not however invalidate any other reasons why
29 * the executable file might be covered by the GNU General Public License.
30 *
31 * This exception applies only to the code released by the
32 * Free Software Foundation under the name GUILE. If you copy
33 * code from other Free Software Foundation releases into a copy of
34 * GUILE, as the General Public License permits, the exception does
35 * not apply to the code that you add in this way. To avoid misleading
36 * anyone as to the status of such modified files, you must delete
37 * this exception notice from them.
38 *
39 * If you write modifications of your own for GUILE, it is your choice
40 * whether to permit this exception to apply to your modifications.
41 * If you do not wish that, delete this exception notice.
42 */
43
44/* "dynl.c" dynamically link&load object files.
45 Author: Aubrey Jaffer
46 Modified for libguile by Marius Vollmer */
47
48#include "_scm.h"
49
50/* Converting a list of SCM strings into a argv-style array. You must
51 have ints disabled for the whole lifetime of the created argv (from
52 before MAKE_ARGV_FROM_STRINGLIST until after
53 MUST_FREE_ARGV). Atleast this is was the documentation for
54 MAKARGVFROMSTRS says, it isn't really used that way.
55
56 This code probably belongs into strings.c */
57
58static char **scm_make_argv_from_stringlist SCM_P ((SCM args, int *argcp,
59 char *subr, int argn));
60
61static char **
62scm_make_argv_from_stringlist (args, argcp, subr, argn)
63 SCM args;
64 int *argcp;
65 char *subr;
66 int argn;
67{
68 char **argv;
69 int argc, i;
70
71 argc = scm_ilength(args);
72 argv = (char **) scm_must_malloc ((1L+argc)*sizeof(char *), subr);
73 for(i = 0; SCM_NNULLP (args); args = SCM_CDR (args), i++) {
74 size_t len;
75 char *dst, *src;
76 SCM str = SCM_CAR (args);
77
78 SCM_ASSERT (SCM_NIMP (str) && SCM_ROSTRINGP (str), str, argn, subr);
79 len = 1 + SCM_ROLENGTH (str);
80 dst = (char *) scm_must_malloc ((long)len, subr);
81 src = SCM_ROCHARS (str);
82 while (len--)
83 dst[len] = src[len];
84 argv[i] = dst;
85 }
86
87 if (argcp)
88 *argcp = argc;
89 argv[argc] = 0;
90 return argv;
91}
92
93static void scm_must_free_argv SCM_P ((char **argv));
94
95static void
96scm_must_free_argv(argv)
97 char **argv;
98{
99 char **av = argv;
100 while(!(*av))
101 free(*(av++));
102 free(argv);
103}
104
105/* Coerce an arbitrary readonly-string into a zero-terminated string.
106 */
107
108static SCM scm_coerce_rostring SCM_P ((SCM rostr, char *subr, int argn));
109
110static SCM
111scm_coerce_rostring (rostr, subr, argn)
112 SCM rostr;
113 char *subr;
114 int argn;
115{
116 SCM_ASSERT (SCM_NIMP (rostr) && SCM_ROSTRINGP (rostr), rostr, argn, subr);
117 if (SCM_SUBSTRP (rostr))
118 rostr = scm_makfromstr (SCM_ROCHARS (rostr), SCM_ROLENGTH (rostr), 0);
119 return rostr;
120}
121
122/* Dispatch to the system dependent files
123 */
124
125#ifdef DYNAMIC_LINKING
126#ifdef HAVE_LIBDL
127#include "dynl-dl.c"
128#else
129#ifdef HAVE_SHL_LOAD
130#include "dynl-shl.c"
131#else
132#ifdef HAVE_DLD
133#include "dynl-dld.c"
134#else /* no dynamic linking available */
135void
136scm_init_dynamic_linking ()
137{
138}
139#endif
140#endif
141#endif
142#else /* dynamic linking disabled */
143void
144scm_init_dynamic_linking ()
145{
146}
147#endif