1 /* ltdl.h -- generic dlopen functions
3 Copyright (C) 1998-2000, 2004-2005, 2007-2008, 2011-2019, 2021-2024
4 Free Software Foundation, Inc.
5 Written by Thomas Tanner, 1998
7 NOTE: The canonical source of this file is maintained with the
8 GNU Libtool package. Report bugs to bug-libtool@gnu.org.
10 GNU Libltdl is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 As a special exception to the GNU Lesser General Public License,
16 if you distribute this file as part of a program or library that
17 is built using GNU Libtool, you may include this file under the
18 same distribution terms that you use for the rest of that program.
20 GNU Libltdl is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License for more details.
25 You should have received a copy of the GNU Lesser General Public
26 License along with GNU Libltdl; see the file COPYING.LIB. If not, a
27 copy can be downloaded from http://www.gnu.org/licenses/lgpl.html,
28 or obtained by writing to the Free Software Foundation, Inc.,
29 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 /* Only include this header file once. */
36 #include <libltdl/lt_system.h>
37 #include <libltdl/lt_error.h>
38 #include <libltdl/lt_dlloader.h>
43 /* LT_STRLEN can be used safely on NULL pointers. */
44 #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0)
46 /* --- DYNAMIC MODULE LOADING API --- */
49 typedef struct lt__handle
*lt_dlhandle
; /* A loaded module. */
51 /* Initialisation and finalisation functions for libltdl. */
52 LT_SCOPE
int lt_dlinit (void);
53 LT_SCOPE
int lt_dlexit (void);
55 /* Module search path manipulation. */
56 LT_SCOPE
int lt_dladdsearchdir (const char *search_dir
);
57 LT_SCOPE
int lt_dlinsertsearchdir (const char *before
,
58 const char *search_dir
);
59 LT_SCOPE
int lt_dlsetsearchpath (const char *search_path
);
60 LT_SCOPE
const char *lt_dlgetsearchpath (void);
61 LT_SCOPE
int lt_dlforeachfile (
62 const char *search_path
,
63 int (*func
) (const char *filename
, void *data
),
66 /* User module loading advisors. */
67 LT_SCOPE
int lt_dladvise_init (lt_dladvise
*advise
);
68 LT_SCOPE
int lt_dladvise_destroy (lt_dladvise
*advise
);
69 LT_SCOPE
int lt_dladvise_ext (lt_dladvise
*advise
);
70 LT_SCOPE
int lt_dladvise_resident (lt_dladvise
*advise
);
71 LT_SCOPE
int lt_dladvise_local (lt_dladvise
*advise
);
72 LT_SCOPE
int lt_dladvise_global (lt_dladvise
*advise
);
73 LT_SCOPE
int lt_dladvise_preload (lt_dladvise
*advise
);
75 /* Portable libltdl versions of the system dlopen() API. */
76 LT_SCOPE lt_dlhandle
lt_dlopen (const char *filename
);
77 LT_SCOPE lt_dlhandle
lt_dlopenext (const char *filename
);
78 LT_SCOPE lt_dlhandle
lt_dlopenadvise (const char *filename
,
80 LT_SCOPE
void * lt_dlsym (lt_dlhandle handle
, const char *name
);
81 LT_SCOPE
const char *lt_dlerror (void);
82 LT_SCOPE
int lt_dlclose (lt_dlhandle handle
);
86 /* --- PRELOADED MODULE SUPPORT --- */
89 /* A preopened symbol. Arrays of this type comprise the exported
90 symbols for a dlpreopened module. */
96 typedef int lt_dlpreload_callback_func (lt_dlhandle handle
);
98 LT_SCOPE
int lt_dlpreload (const lt_dlsymlist
*preloaded
);
99 LT_SCOPE
int lt_dlpreload_default (const lt_dlsymlist
*preloaded
);
100 LT_SCOPE
int lt_dlpreload_open (const char *originator
,
101 lt_dlpreload_callback_func
*func
);
103 #define lt_preloaded_symbols lt__PROGRAM__LTX_preloaded_symbols
104 /* Ensure C linkage. */
105 extern LT_DLSYM_CONST lt_dlsymlist lt__PROGRAM__LTX_preloaded_symbols
[];
107 #define LTDL_SET_PRELOADED_SYMBOLS() \
108 lt_dlpreload_default(lt_preloaded_symbols)
112 /* --- MODULE INFORMATION --- */
115 /* Associating user data with loaded modules. */
116 typedef void * lt_dlinterface_id
;
117 typedef int lt_dlhandle_interface (lt_dlhandle handle
, const char *id_string
);
119 LT_SCOPE lt_dlinterface_id
lt_dlinterface_register (const char *id_string
,
120 lt_dlhandle_interface
*iface
);
121 LT_SCOPE
void lt_dlinterface_free (lt_dlinterface_id key
);
122 LT_SCOPE
void * lt_dlcaller_set_data (lt_dlinterface_id key
,
123 lt_dlhandle handle
, void *data
);
124 LT_SCOPE
void * lt_dlcaller_get_data (lt_dlinterface_id key
,
128 /* Read only information pertaining to a loaded module. */
130 char * filename
; /* file name */
131 char * name
; /* module name */
132 int ref_count
; /* number of times lt_dlopened minus
133 number of times lt_dlclosed. */
134 unsigned int is_resident
:1; /* module can't be unloaded. */
135 unsigned int is_symglobal
:1; /* module symbols can satisfy
136 subsequently loaded modules. */
137 unsigned int is_symlocal
:1; /* module symbols are only available
141 LT_SCOPE
const lt_dlinfo
*lt_dlgetinfo (lt_dlhandle handle
);
143 LT_SCOPE lt_dlhandle
lt_dlhandle_iterate (lt_dlinterface_id iface
,
145 LT_SCOPE lt_dlhandle
lt_dlhandle_fetch (lt_dlinterface_id iface
,
146 const char *module_name
);
147 LT_SCOPE
int lt_dlhandle_map (lt_dlinterface_id iface
,
148 int (*func
) (lt_dlhandle handle
, void *data
),
153 /* Deprecated module residency management API. */
154 LT_SCOPE
int lt_dlmakeresident (lt_dlhandle handle
);
155 LT_SCOPE
int lt_dlisresident (lt_dlhandle handle
);
157 #define lt_ptr void *
161 #endif /*!defined LTDL_H*/