libtool/libltdl/ltdl.c

1826 lines
37 KiB
C
Raw Normal View History

/* ltdl.c -- system independent dlopen wrapper
Copyright (C) 1998-2000 Free Software Foundation, Inc.
Originally by Thomas Tanner <tanner@ffii.org>
This file is part of GNU Libtool.
1998-11-24 05:26:38 +08:00
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
As a special exception to the GNU Library General Public License,
if you distribute this file as part of a program that uses GNU libtool
to create libraries and programs, you may include it under the same
distribution terms that you use for the rest of that program.
1998-11-24 05:26:38 +08:00
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
1998-11-24 05:26:38 +08:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
1998-11-24 05:26:38 +08:00
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
1998-11-24 05:26:38 +08:00
*/
#define _LTDL_COMPILE_
#if HAVE_CONFIG_H
#include <config.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_STRINGS_H
1998-12-02 21:05:23 +08:00
#include <strings.h>
#endif
1998-12-19 06:23:51 +08:00
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#if HAVE_MEMORY_H
#include <memory.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STDIO_H
1998-11-24 05:26:38 +08:00
#include <stdio.h>
#endif
#include "ltdl.h"
1998-11-24 05:26:38 +08:00
#ifdef DLL_EXPORT
# define LTDL_GLOBAL_DATA __declspec(dllexport)
#else
# define LTDL_GLOBAL_DATA
#endif
1999-01-17 19:19:40 +08:00
/* max. filename length */
#ifndef LTDL_FILENAME_MAX
#define LTDL_FILENAME_MAX 1024
1999-01-17 19:19:40 +08:00
#endif
#undef LTDL_READTEXT_MODE
/* fopen() mode flags for reading a text file */
#ifdef _WIN32
#define LTDL_READTEXT_MODE "rt"
#else
#define LTDL_READTEXT_MODE "r"
#endif
#undef LTDL_SYMBOL_LENGTH
/* This is the maximum symbol size that won't require malloc/free */
#define LTDL_SYMBOL_LENGTH 128
1999-01-17 19:19:40 +08:00
#undef LTDL_SYMBOL_OVERHEAD
/* This accounts for the _LTX_ separator */
#define LTDL_SYMBOL_OVERHEAD 5
1999-01-17 19:19:40 +08:00
static const char objdir[] = LTDL_OBJDIR;
#ifdef LTDL_SHLIB_EXT
static const char shlib_ext[] = LTDL_SHLIB_EXT;
#endif
#ifdef LTDL_SYSSEARCHPATH
static const char sys_search_path[] = LTDL_SYSSEARCHPATH;
#endif
static const char unknown_error[] = "unknown error";
static const char dlopen_not_supported_error[] = "dlopen support not available";
static const char file_not_found_error[] = "file not found";
static const char deplib_not_found_error[] = "dependency library not found";
static const char no_symbols_error[] = "no symbols defined";
static const char cannot_open_error[] = "can't open the module";
static const char cannot_close_error[] = "can't close the module";
static const char symbol_error[] = "symbol not found";
static const char memory_error[] = "not enough memory";
static const char invalid_handle_error[] = "invalid handle";
static const char buffer_overflow_error[] = "internal buffer overflow";
static const char shutdown_error[] = "library already shutdown";
1999-01-10 04:05:55 +08:00
1999-01-15 00:31:23 +08:00
static const char *last_error = 0;
LTDL_GLOBAL_DATA lt_ptr_t (*lt_dlmalloc) LTDL_PARAMS((size_t size)) = (lt_ptr_t(*)LTDL_PARAMS((size_t)))malloc;
LTDL_GLOBAL_DATA void (*lt_dlfree) LTDL_PARAMS((lt_ptr_t ptr)) = (void(*)LTDL_PARAMS((lt_ptr_t)))free;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
typedef struct lt_dltype_t {
struct lt_dltype_t *next;
1999-01-15 00:31:23 +08:00
const char *sym_prefix; /* prefix for symbols */
int (*mod_init) LTDL_PARAMS((void));
int (*mod_exit) LTDL_PARAMS((void));
int (*lib_open) LTDL_PARAMS((lt_dlhandle handle, const char *filename));
int (*lib_close) LTDL_PARAMS((lt_dlhandle handle));
lt_ptr_t (*find_sym) LTDL_PARAMS((lt_dlhandle handle, const char *symbol));
} lt_dltype_t;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-17 19:19:40 +08:00
#define LTDL_TYPE_TOP 0
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1998-12-02 21:05:23 +08:00
typedef struct lt_dlhandle_t {
struct lt_dlhandle_t *next;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
lt_dltype_t *type; /* dlopening interface */
lt_dlinfo info;
1999-01-13 04:42:47 +08:00
int depcount; /* number of dependencies */
lt_dlhandle *deplibs; /* dependencies */
1998-12-19 06:23:51 +08:00
lt_ptr_t handle; /* system handle */
lt_ptr_t system; /* system specific data */
lt_ptr_t app_private; /* application private data */
1998-12-02 21:05:23 +08:00
} lt_dlhandle_t;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#undef strdup
#define strdup xstrdup
1998-11-24 05:26:38 +08:00
static inline char *
1998-12-02 21:05:23 +08:00
strdup(str)
1998-12-20 03:30:30 +08:00
const char *str;
1998-11-24 05:26:38 +08:00
{
char *tmp;
if (!str)
return 0;
tmp = (char*) lt_dlmalloc(strlen(str)+1);
1998-11-24 05:26:38 +08:00
if (tmp)
strcpy(tmp, str);
return tmp;
}
1998-12-23 21:28:28 +08:00
#if ! HAVE_STRCHR
# if HAVE_INDEX
# define strchr index
# else
# define strchr xstrchr
static inline const char*
1998-12-23 21:28:28 +08:00
strchr(str, ch)
const char *str;
int ch;
{
const char *p;
for (p = str; *p != (char)ch && *p != '\0'; p++)
1998-12-23 21:28:28 +08:00
/*NOWORK*/;
1998-12-25 18:39:59 +08:00
return (*p == (char)ch) ? p : 0;
1998-12-23 21:28:28 +08:00
}
# endif
#endif
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#if ! HAVE_STRRCHR
# if HAVE_RINDEX
1998-12-02 21:05:23 +08:00
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
# define strrchr rindex
# else
# define strrchr xstrrchr
static inline const char*
1998-12-02 21:05:23 +08:00
strrchr(str, ch)
1998-12-20 03:30:30 +08:00
const char *str;
int ch;
1998-12-02 21:05:23 +08:00
{
1998-12-20 03:30:30 +08:00
const char *p;
1998-12-02 21:05:23 +08:00
for (p = str; *p != '\0'; p++)
1998-12-20 03:30:30 +08:00
/*NOWORK*/;
1998-12-02 21:05:23 +08:00
while (*p != (char)ch && p >= str)
1998-12-20 03:30:30 +08:00
p--;
1998-12-02 21:05:23 +08:00
1998-12-25 18:39:59 +08:00
return (*p == (char)ch) ? p : 0;
1998-12-02 21:05:23 +08:00
}
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
# endif
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#endif
/* The Cygwin dlopen implementation prints a spurious error message to
stderr if its call to LoadLibrary() fails for any reason. We can
mitigate this by not using the Cygwin implementation, and falling
back to our own LoadLibrary() wrapper. */
#if HAVE_LIBDL && !defined(__CYGWIN__)
/* dynamic linking with dlopen/dlsym */
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#if HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#ifdef RTLD_GLOBAL
# define LTDL_GLOBAL RTLD_GLOBAL
1999-01-10 04:05:55 +08:00
#else
# ifdef DL_GLOBAL
1999-01-10 04:05:55 +08:00
# define LTDL_GLOBAL DL_GLOBAL
# else
# define LTDL_GLOBAL 0
# endif
#endif
/* We may have to define LTDL_LAZY_OR_NOW in the command line if we
find out it does not work in some platform. */
#ifndef LTDL_LAZY_OR_NOW
# ifdef RTLD_LAZY
# define LTDL_LAZY_OR_NOW RTLD_LAZY
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
# else
# ifdef DL_LAZY
# define LTDL_LAZY_OR_NOW DL_LAZY
# else
# ifdef RTLD_NOW
# define LTDL_LAZY_OR_NOW RTLD_NOW
# else
# ifdef DL_NOW
# define LTDL_LAZY_OR_NOW DL_NOW
# else
# define LTDL_LAZY_OR_NOW 0
# endif
# endif
# endif
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
# endif
#endif
1998-11-24 05:26:38 +08:00
static int
sys_dl_init LTDL_PARAMS((void))
{
1998-11-24 05:26:38 +08:00
return 0;
}
1998-11-24 05:26:38 +08:00
static int
sys_dl_exit LTDL_PARAMS((void))
{
1998-11-24 05:26:38 +08:00
return 0;
}
1998-11-24 05:26:38 +08:00
static int
sys_dl_open (handle, filename)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *filename;
1998-11-24 05:26:38 +08:00
{
handle->handle = dlopen(filename, LTDL_GLOBAL | LTDL_LAZY_OR_NOW);
1999-01-10 04:05:55 +08:00
if (!handle->handle) {
#if HAVE_DLERROR
1999-01-10 04:05:55 +08:00
last_error = dlerror();
#else
last_error = cannot_open_error;
#endif
1999-01-10 04:05:55 +08:00
return 1;
}
return 0;
1998-11-24 05:26:38 +08:00
}
static int
sys_dl_close (handle)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
{
1999-01-10 04:05:55 +08:00
if (dlclose(handle->handle) != 0) {
#if HAVE_DLERROR
1999-01-10 04:05:55 +08:00
last_error = dlerror();
#else
last_error = cannot_close_error;
#endif
1999-01-10 04:05:55 +08:00
return 1;
}
return 0;
}
1998-12-19 06:23:51 +08:00
static lt_ptr_t
sys_dl_sym (handle, symbol)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *symbol;
{
1999-01-10 04:05:55 +08:00
lt_ptr_t address = dlsym(handle->handle, symbol);
1999-01-17 19:19:40 +08:00
if (!address)
#if HAVE_DLERROR
1999-01-10 04:05:55 +08:00
last_error = dlerror();
#else
last_error = symbol_error;
#endif
1999-01-10 04:05:55 +08:00
return address;
}
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
static
lt_dltype_t
1999-01-15 00:31:23 +08:00
#ifdef NEED_USCORE
sys_dl = { LTDL_TYPE_TOP, "_", sys_dl_init, sys_dl_exit,
sys_dl_open, sys_dl_close, sys_dl_sym };
1999-01-15 00:31:23 +08:00
#else
sys_dl = { LTDL_TYPE_TOP, 0, sys_dl_init, sys_dl_exit,
sys_dl_open, sys_dl_close, sys_dl_sym };
1999-01-15 00:31:23 +08:00
#endif
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-17 19:19:40 +08:00
#undef LTDL_TYPE_TOP
#define LTDL_TYPE_TOP &sys_dl
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#endif
#if HAVE_SHL_LOAD
1999-01-17 19:19:40 +08:00
/* dynamic linking with shl_load (HP-UX) (comments from gmodule) */
#ifdef HAVE_DL_H
#include <dl.h>
#endif
1998-12-25 18:39:59 +08:00
/* some flags are missing on some systems, so we provide
* harmless defaults.
*
* Mandatory:
* BIND_IMMEDIATE - Resolve symbol references when the library is loaded.
* BIND_DEFERRED - Delay code symbol resolution until actual reference.
*
* Optionally:
* BIND_FIRST - Place the library at the head of the symbol search order.
* BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all unsatisfied
* symbols as fatal. This flag allows binding of unsatisfied code
* symbols to be deferred until use.
* [Perl: For certain libraries, like DCE, deferred binding often
* causes run time problems. Adding BIND_NONFATAL to BIND_IMMEDIATE
* still allows unresolved references in situations like this.]
* BIND_NOSTART - Do not call the initializer for the shared library when the
* library is loaded, nor on a future call to shl_unload().
* BIND_VERBOSE - Print verbose messages concerning possible unsatisfied symbols.
*
* hp9000s700/hp9000s800:
* BIND_RESTRICTED - Restrict symbols visible by the library to those present at
* library load time.
* DYNAMIC_PATH - Allow the loader to dynamically search for the library specified
* by the path argument.
*/
1999-01-10 04:05:55 +08:00
1998-12-25 18:39:59 +08:00
#ifndef DYNAMIC_PATH
#define DYNAMIC_PATH 0
#endif /* DYNAMIC_PATH */
#ifndef BIND_RESTRICTED
#define BIND_RESTRICTED 0
#endif /* BIND_RESTRICTED */
#define LTDL_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH)
1998-12-25 18:39:59 +08:00
1998-11-24 05:26:38 +08:00
static int
sys_shl_init LTDL_PARAMS((void))
1998-11-24 05:26:38 +08:00
{
return 0;
}
static int
sys_shl_exit LTDL_PARAMS((void))
{
1998-11-24 05:26:38 +08:00
return 0;
}
1998-11-24 05:26:38 +08:00
static int
sys_shl_open (handle, filename)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *filename;
{
1999-01-14 05:39:14 +08:00
handle->handle = shl_load(filename, LTDL_BIND_FLAGS, 0L);
1999-01-10 04:05:55 +08:00
if (!handle->handle) {
last_error = cannot_open_error;
1999-01-10 04:05:55 +08:00
return 1;
}
return 0;
}
1998-11-24 05:26:38 +08:00
static int
sys_shl_close (handle)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
{
if (shl_unload((shl_t) (handle->handle)) != 0) {
last_error = cannot_close_error;
1999-01-10 04:05:55 +08:00
return 1;
}
1998-11-24 05:26:38 +08:00
return 0;
}
1998-12-19 06:23:51 +08:00
static lt_ptr_t
sys_shl_sym (handle, symbol)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *symbol;
{
1999-01-10 04:05:55 +08:00
lt_ptr_t address;
1998-12-25 18:39:59 +08:00
if (handle->handle && shl_findsym((shl_t*) &(handle->handle),
symbol, TYPE_UNDEFINED, &address) == 0)
if (address)
return address;
last_error = symbol_error;
return 0;
}
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
static
lt_dltype_t
sys_shl = { LTDL_TYPE_TOP, 0, sys_shl_init, sys_shl_exit,
sys_shl_open, sys_shl_close, sys_shl_sym };
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-17 19:19:40 +08:00
#undef LTDL_TYPE_TOP
#define LTDL_TYPE_TOP &sys_shl
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#endif
#if HAVE_DLD
/* dynamic linking with dld */
#if HAVE_DLD_H
#include <dld.h>
#endif
1998-11-24 05:26:38 +08:00
static int
sys_dld_init LTDL_PARAMS((void))
{
1998-11-24 05:26:38 +08:00
return 0;
}
1998-11-24 05:26:38 +08:00
static int
sys_dld_exit LTDL_PARAMS((void))
{
1998-11-24 05:26:38 +08:00
return 0;
}
1998-11-24 05:26:38 +08:00
static int
sys_dld_open (handle, filename)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *filename;
{
1999-01-13 04:42:47 +08:00
handle->handle = strdup(filename);
if (!handle->handle) {
last_error = memory_error;
1999-01-13 04:42:47 +08:00
return 1;
}
1999-01-10 04:05:55 +08:00
if (dld_link(filename) != 0) {
last_error = cannot_open_error;
lt_dlfree(handle->handle);
1998-11-24 05:26:38 +08:00
return 1;
1999-01-10 04:05:55 +08:00
}
1998-11-24 05:26:38 +08:00
return 0;
}
static int
sys_dld_close (handle)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
1998-11-24 05:26:38 +08:00
{
1999-01-10 04:05:55 +08:00
if (dld_unlink_by_file((char*)(handle->handle), 1) != 0) {
last_error = cannot_close_error;
1999-01-10 04:05:55 +08:00
return 1;
}
lt_dlfree(handle->filename);
1998-11-24 05:26:38 +08:00
return 0;
}
1998-12-19 06:23:51 +08:00
static lt_ptr_t
sys_dld_sym (handle, symbol)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *symbol;
{
1999-01-10 04:05:55 +08:00
lt_ptr_t address = dld_get_func(symbol);
1999-01-17 19:19:40 +08:00
if (!address)
last_error = symbol_error;
1999-01-10 04:05:55 +08:00
return address;
}
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
static
lt_dltype_t
sys_dld = { LTDL_TYPE_TOP, 0, sys_dld_init, sys_dld_exit,
sys_dld_open, sys_dld_close, sys_dld_sym };
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-17 19:19:40 +08:00
#undef LTDL_TYPE_TOP
#define LTDL_TYPE_TOP &sys_dld
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#endif
#ifdef _WIN32
/* dynamic linking for Win32 */
#include <windows.h>
1998-11-24 05:26:38 +08:00
static int
sys_wll_init LTDL_PARAMS((void))
{
1998-11-24 05:26:38 +08:00
return 0;
}
1998-11-24 05:26:38 +08:00
static int
sys_wll_exit LTDL_PARAMS((void))
{
1998-11-24 05:26:38 +08:00
return 0;
}
/* Forward declaration; required to implement handle search below. */
static lt_dlhandle handles;
1998-11-24 05:26:38 +08:00
static int
sys_wll_open (handle, filename)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *filename;
{
lt_dlhandle cur;
char *searchname = NULL;
char *ext = strrchr(filename, '.');
if (ext) {
/* FILENAME already has an extension. */
searchname = strdup(filename);
} else {
/* Append a `.' to stop Windows from adding an
implicit `.dll' extension. */
searchname = (char*)lt_dlmalloc(2+ strlen(filename));
strcpy(searchname, filename);
strcat(searchname, ".");
}
handle->handle = LoadLibrary(searchname);
lt_dlfree(searchname);
/* libltdl expects this function to fail if it is unable
to physically load the library. Sadly, LoadLibrary
will search the loaded libraries for a match and return
one of them if the path search load fails.
We check whether LoadLibrary is returning a handle to
an already loaded module, and simulate failure if we
find one. */
cur = handles;
while (cur) {
if (!cur->handle) {
cur = 0;
break;
}
if (cur->handle == handle->handle)
break;
cur = cur->next;
}
if (cur || !handle->handle) {
last_error = cannot_open_error;
1999-01-10 04:05:55 +08:00
return 1;
}
1999-01-10 04:05:55 +08:00
return 0;
1998-11-24 05:26:38 +08:00
}
static int
sys_wll_close (handle)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
1998-11-24 05:26:38 +08:00
{
if (FreeLibrary(handle->handle) == 0) {
last_error = cannot_close_error;
1999-01-10 04:05:55 +08:00
return 1;
}
1998-11-24 05:26:38 +08:00
return 0;
}
1998-12-19 06:23:51 +08:00
static lt_ptr_t
sys_wll_sym (handle, symbol)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *symbol;
{
1999-01-10 04:05:55 +08:00
lt_ptr_t address = GetProcAddress(handle->handle, symbol);
1999-01-17 19:19:40 +08:00
if (!address)
last_error = symbol_error;
1999-01-10 04:05:55 +08:00
return address;
}
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
static
lt_dltype_t
sys_wll = { LTDL_TYPE_TOP, 0, sys_wll_init, sys_wll_exit,
sys_wll_open, sys_wll_close, sys_wll_sym };
1999-01-17 19:19:40 +08:00
#undef LTDL_TYPE_TOP
#define LTDL_TYPE_TOP &sys_wll
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
#endif
#ifdef __BEOS__
/* dynamic linking for BeOS */
#include <kernel/image.h>
static int
sys_bedl_init LTDL_PARAMS((void))
{
return 0;
}
static int
sys_bedl_exit LTDL_PARAMS((void))
{
return 0;
}
static int
sys_bedl_open (handle, filename)
lt_dlhandle handle;
const char *filename;
{
image_id image = 0;
if (filename) {
image = load_add_on(filename);
} else {
image_info info;
int32 cookie = 0;
if (get_next_image_info(0, &cookie, &info) == B_OK)
image = load_add_on(info.name);
}
if (image <= 0) {
last_error = cannot_open_error;
return 1;
}
handle->handle = (void*) image;
return 0;
}
static int
sys_bedl_close (handle)
lt_dlhandle handle;
{
if (unload_add_on((image_id)handle->handle) != B_OK) {
last_error = cannot_close_error;
return 1;
}
return 0;
}
static lt_ptr_t
sys_bedl_sym (handle, symbol)
lt_dlhandle handle;
const char *symbol;
{
lt_ptr_t address = 0;
image_id image = (image_id)handle->handle;
if (get_image_symbol(image, symbol, B_SYMBOL_TYPE_ANY,
&address) != B_OK) {
last_error = symbol_error;
return 0;
}
return address;
}
static
lt_dltype_t
sys_bedl = { LTDL_TYPE_TOP, 0, sys_bedl_init, sys_bedl_exit,
sys_bedl_open, sys_bedl_close, sys_bedl_sym };
#undef LTDL_TYPE_TOP
#define LTDL_TYPE_TOP &sys_bedl
#endif
1999-01-14 05:39:14 +08:00
/* emulate dynamic linking using preloaded_symbols */
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-13 04:42:47 +08:00
typedef struct lt_dlsymlists_t {
struct lt_dlsymlists_t *next;
1999-01-14 05:39:14 +08:00
const lt_dlsymlist *syms;
1999-01-13 04:42:47 +08:00
} lt_dlsymlists_t;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-15 00:31:23 +08:00
static const lt_dlsymlist *default_preloaded_symbols = 0;
static lt_dlsymlists_t *preloaded_symbols = 0;
1998-11-24 05:26:38 +08:00
static int
presym_init LTDL_PARAMS((void))
{
1999-01-15 00:31:23 +08:00
preloaded_symbols = 0;
if (default_preloaded_symbols)
1999-01-17 19:19:40 +08:00
return lt_dlpreload(default_preloaded_symbols);
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
return 0;
}
static int
presym_free_symlists LTDL_PARAMS((void))
1999-01-13 04:42:47 +08:00
{
lt_dlsymlists_t *lists = preloaded_symbols;
while (lists) {
lt_dlsymlists_t *tmp = lists;
lists = lists->next;
lt_dlfree(tmp);
1999-01-13 04:42:47 +08:00
}
preloaded_symbols = 0;
return 0;
1999-01-13 04:42:47 +08:00
}
1998-11-24 05:26:38 +08:00
static int
presym_exit LTDL_PARAMS((void))
{
1999-01-15 00:31:23 +08:00
presym_free_symlists();
1999-01-13 04:42:47 +08:00
return 0;
}
static int
1999-01-14 05:39:14 +08:00
presym_add_symlist (preloaded)
const lt_dlsymlist *preloaded;
1999-01-13 04:42:47 +08:00
{
lt_dlsymlists_t *tmp;
lt_dlsymlists_t *lists = preloaded_symbols;
while (lists) {
if (lists->syms == preloaded)
return 0;
lists = lists->next;
}
tmp = (lt_dlsymlists_t*) lt_dlmalloc(sizeof(lt_dlsymlists_t));
1999-01-13 04:42:47 +08:00
if (!tmp) {
last_error = memory_error;
return 1;
}
tmp->syms = preloaded;
tmp->next = 0;
if (!preloaded_symbols)
preloaded_symbols = tmp;
else {
/* append to the end */
lists = preloaded_symbols;
while (lists->next)
lists = lists->next;
lists->next = tmp;
}
return 0;
}
1998-11-24 05:26:38 +08:00
static int
1999-01-14 05:39:14 +08:00
presym_open (handle, filename)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *filename;
1998-11-24 05:26:38 +08:00
{
1999-01-13 04:42:47 +08:00
lt_dlsymlists_t *lists = preloaded_symbols;
1999-01-13 04:42:47 +08:00
if (!lists) {
1999-01-10 04:05:55 +08:00
last_error = no_symbols_error;
return 1;
}
if (!filename)
filename = "@PROGRAM@";
1999-01-13 04:42:47 +08:00
while (lists) {
1999-01-14 05:39:14 +08:00
const lt_dlsymlist *syms = lists->syms;
1999-01-13 04:42:47 +08:00
while (syms->name) {
if (!syms->address &&
strcmp(syms->name, filename) == 0) {
1999-01-14 05:39:14 +08:00
handle->handle = (lt_ptr_t) syms;
1999-01-13 04:42:47 +08:00
return 0;
}
syms++;
}
lists = lists->next;
1999-01-10 04:05:55 +08:00
}
1999-01-13 04:42:47 +08:00
last_error = file_not_found_error;
return 1;
1998-11-24 05:26:38 +08:00
}
static int
1999-01-14 05:39:14 +08:00
presym_close (handle)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
{
/* Just to silence gcc -Wall */
handle = 0;
1998-11-24 05:26:38 +08:00
return 0;
}
1998-12-19 06:23:51 +08:00
static lt_ptr_t
1999-01-14 05:39:14 +08:00
presym_sym (handle, symbol)
1998-12-20 03:30:30 +08:00
lt_dlhandle handle;
const char *symbol;
{
1999-01-13 04:42:47 +08:00
lt_dlsymlist *syms = (lt_dlsymlist*)(handle->handle);
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-13 04:42:47 +08:00
syms++;
while (syms->address) {
if (strcmp(syms->name, symbol) == 0)
1999-01-13 04:42:47 +08:00
return syms->address;
syms++;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
}
1999-01-10 04:05:55 +08:00
last_error = symbol_error;
return 0;
}
static
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
lt_dltype_t
1999-01-17 19:19:40 +08:00
presym = { LTDL_TYPE_TOP, 0, presym_init, presym_exit,
1999-01-14 05:39:14 +08:00
presym_open, presym_close, presym_sym };
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1999-01-17 19:19:40 +08:00
#undef LTDL_TYPE_TOP
#define LTDL_TYPE_TOP &presym
static char *user_search_path = 0;
1999-01-17 19:19:40 +08:00
static lt_dlhandle handles = 0;
1998-11-24 05:26:38 +08:00
static int initialized = 0;
static lt_dltype_t *types = LTDL_TYPE_TOP;
1999-01-17 19:19:40 +08:00
#undef LTDL_TYPE_TOP
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
1998-11-24 05:26:38 +08:00
int
lt_dlinit LTDL_PARAMS((void))
{
1998-12-20 03:30:30 +08:00
/* initialize libltdl */
lt_dltype_t **type = &types;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
int typecount = 0;
1998-11-24 05:26:38 +08:00
if (initialized) { /* Initialize only at first call. */
initialized++;
return 0;
}
handles = 0;
user_search_path = 0; /* empty search path */
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
while (*type) {
if ((*type)->mod_init())
*type = (*type)->next; /* Remove it from the list */
else {
type = &(*type)->next; /* Keep it */
1998-12-20 03:30:30 +08:00
typecount++;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
}
}
1999-01-10 04:05:55 +08:00
if (typecount == 0) {
1999-01-13 04:42:47 +08:00
last_error = dlopen_not_supported_error;
1998-11-24 05:26:38 +08:00
return 1;
1999-01-10 04:05:55 +08:00
}
last_error = 0;
1998-11-24 05:26:38 +08:00
initialized = 1;
return 0;
}
1999-01-13 04:42:47 +08:00
int
1999-01-17 19:19:40 +08:00
lt_dlpreload (preloaded)
1999-01-14 05:39:14 +08:00
const lt_dlsymlist *preloaded;
{
1999-01-13 04:42:47 +08:00
if (preloaded)
1999-01-14 05:39:14 +08:00
return presym_add_symlist(preloaded);
1999-01-17 19:19:40 +08:00
presym_free_symlists();
if (default_preloaded_symbols)
return lt_dlpreload(default_preloaded_symbols);
return 0;
}
1999-01-15 00:31:23 +08:00
int
1999-01-17 19:19:40 +08:00
lt_dlpreload_default (preloaded)
1999-01-15 00:31:23 +08:00
const lt_dlsymlist *preloaded;
{
default_preloaded_symbols = preloaded;
return 0;
}
1998-11-24 05:26:38 +08:00
int
lt_dlexit LTDL_PARAMS((void))
{
1998-12-20 03:30:30 +08:00
/* shut down libltdl */
lt_dltype_t *type = types;
int errors, level;
1998-11-24 05:26:38 +08:00
1999-01-10 04:05:55 +08:00
if (!initialized) {
last_error = shutdown_error;
return 1;
}
1998-12-20 03:30:30 +08:00
if (initialized != 1) { /* shut down only at last call. */
1998-11-24 05:26:38 +08:00
initialized--;
return 0;
}
/* close all modules */
1998-12-23 21:28:28 +08:00
errors = 0;
for (level = 1; handles; level++) {
lt_dlhandle cur = handles;
while (cur) {
lt_dlhandle tmp = cur;
cur = cur->next;
if (tmp->info.ref_count <= level)
if (lt_dlclose(tmp))
errors++;
}
}
1998-11-24 05:26:38 +08:00
initialized = 0;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
while (type) {
if (type->mod_exit())
1998-12-23 21:28:28 +08:00
errors++;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
type = type->next;
}
1998-12-23 21:28:28 +08:00
return errors;
}
1998-12-20 03:30:30 +08:00
static int
1998-12-23 21:28:28 +08:00
tryall_dlopen (handle, filename)
lt_dlhandle *handle;
const char *filename;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
{
1998-12-23 21:28:28 +08:00
lt_dlhandle cur;
lt_dltype_t *type = types;
1999-01-10 04:05:55 +08:00
const char *saved_error = last_error;
1998-12-23 21:28:28 +08:00
/* check whether the module was already opened */
cur = handles;
while (cur) {
/* try to dlopen the program itself? */
if (!cur->info.filename && !filename)
break;
if (cur->info.filename && filename &&
strcmp(cur->info.filename, filename) == 0)
break;
1998-12-23 21:28:28 +08:00
cur = cur->next;
}
1998-12-23 21:28:28 +08:00
if (cur) {
cur->info.ref_count++;
1998-12-23 21:28:28 +08:00
*handle = cur;
return 0;
}
cur = *handle;
if (filename) {
cur->info.filename = strdup(filename);
if (!cur->info.filename) {
last_error = memory_error;
return 1;
}
} else
cur->info.filename = 0;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
while (type) {
if (type->lib_open(cur, filename) == 0)
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
break;
type = type->next;
}
1999-01-13 04:42:47 +08:00
if (!type) {
if (cur->info.filename)
lt_dlfree(cur->info.filename);
1999-01-10 04:05:55 +08:00
return 1;
1999-01-13 04:42:47 +08:00
}
cur->type = type;
1999-01-10 04:05:55 +08:00
last_error = saved_error;
return 0;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
}
1998-12-20 03:30:30 +08:00
static int
find_module (handle, dir, libdir, dlname, old_name, installed)
lt_dlhandle *handle;
const char *dir;
const char *libdir;
1998-12-20 03:30:30 +08:00
const char *dlname;
const char *old_name;
int installed;
1998-12-20 03:30:30 +08:00
{
int error;
char *filename;
/* try to open the old library first; if it was dlpreopened,
we want the preopened version of it, even if a dlopenable
module is available */
if (old_name && tryall_dlopen(handle, old_name) == 0)
return 0;
/* try to open the dynamic library */
if (dlname) {
/* try to open the installed module */
if (installed && libdir) {
filename = (char*)
lt_dlmalloc(strlen(libdir)+1+strlen(dlname)+1);
if (!filename) {
last_error = memory_error;
return 1;
}
sprintf (filename, "%s/%s", libdir, dlname);
error = tryall_dlopen(handle, filename) != 0;
lt_dlfree(filename);
if (!error)
return 0;
}
/* try to open the not-installed module */
if (!installed) {
filename = (char*)
lt_dlmalloc((dir ? strlen(dir) : 0)
+ strlen(objdir) + strlen(dlname) + 1);
if (!filename) {
last_error = memory_error;
return 1;
}
if (dir)
strcpy(filename, dir);
else
*filename = 0;
strcat(filename, objdir);
strcat(filename, dlname);
error = tryall_dlopen(handle, filename) != 0;
lt_dlfree(filename);
if (!error)
return 0;
1999-01-09 17:51:44 +08:00
}
/* maybe it was moved to another directory */
{
filename = (char*)
lt_dlmalloc((dir ? strlen(dir) : 0)
+ strlen(dlname) + 1);
if (dir)
strcpy(filename, dir);
else
*filename = 0;
strcat(filename, dlname);
error = tryall_dlopen(handle, filename) != 0;
lt_dlfree(filename);
if (!error)
return 0;
1999-01-13 04:42:47 +08:00
}
}
return 1;
}
1998-12-20 03:30:30 +08:00
static char*
canonicalize_path (path)
const char *path;
{
char *canonical = NULL;
if (path && *path) {
char *ptr = strdup (path);
canonical = ptr;
#ifdef LTDL_DIRSEP_CHAR
/* Avoid this overhead where '/' is the only separator. */
while (ptr = strchr (ptr, LTDL_DIRSEP_CHAR))
*ptr++ = '/';
#endif
}
return canonical;
}
static lt_ptr_t
find_file (basename, search_path, pdir, handle)
1999-01-13 04:42:47 +08:00
const char *basename;
const char *search_path;
char **pdir;
lt_dlhandle *handle;
1999-01-13 04:42:47 +08:00
{
/* when handle != NULL search a library, otherwise a file */
/* return NULL on failure, otherwise the file/handle */
lt_ptr_t result = 0;
char *filename = 0;
int filenamesize = 0;
int lenbase = strlen(basename);
char *canonical = 0, *next = 0;
if (!search_path || !*search_path) {
1999-01-13 04:42:47 +08:00
last_error = file_not_found_error;
return 0;
}
canonical = canonicalize_path (search_path);
if (!canonical) {
last_error = memory_error;
goto cleanup;
}
next = canonical;
while (next) {
int lendir;
char *cur = next;
next = strchr(cur, LTDL_PATHSEP_CHAR);
if (!next)
next = cur + strlen(cur);
lendir = next - cur;
if (*next == LTDL_PATHSEP_CHAR)
++next;
else
next = 0;
if (lendir == 0)
continue;
if (lendir + 1 + lenbase >= filenamesize) {
if (filename)
lt_dlfree(filename);
filenamesize = lendir + 1 + lenbase + 1;
filename = (char*) lt_dlmalloc(filenamesize);
if (!filename) {
last_error = memory_error;
goto cleanup;
}
}
strncpy(filename, cur, lendir);
if (filename[lendir-1] != '/')
filename[lendir++] = '/';
strcpy(filename+lendir, basename);
if (handle) {
if (tryall_dlopen(handle, filename) == 0) {
result = (lt_ptr_t) handle;
goto cleanup;
}
} else {
FILE *file = fopen(filename, LTDL_READTEXT_MODE);
if (file) {
if (*pdir)
lt_dlfree(*pdir);
filename[lendir] = '\0';
*pdir = strdup(filename);
if (!*pdir) {
/* We could have even avoided the
strdup, but there would be some
memory overhead. */
*pdir = filename;
} else
filename = NULL;
result = (lt_ptr_t) file;
goto cleanup;
}
1999-01-13 04:42:47 +08:00
}
}
last_error = file_not_found_error;
cleanup:
if (filename)
lt_dlfree(filename);
if (canonical)
lt_dlfree(canonical);
return result;
1999-01-13 04:42:47 +08:00
}
static int
load_deplibs(handle, deplibs)
1999-01-17 19:19:40 +08:00
lt_dlhandle handle;
char *deplibs;
1999-01-13 04:42:47 +08:00
{
char *p, *save_search_path;
int i;
int ret = 1, depcount = 0;
char **names = 0;
lt_dlhandle *handles = 0;
1999-01-17 19:19:40 +08:00
handle->depcount = 0;
if (!deplibs)
return 0;
save_search_path = strdup(user_search_path);
if (user_search_path && !save_search_path) {
last_error = memory_error;
return 1;
}
p = deplibs;
/* extract search paths and count deplibs */
while (*p) {
if (!isspace(*p)) {
char *end = p+1;
while (*end && !isspace(*end)) end++;
if (strncmp(p, "-L", 2) == 0 ||
strncmp(p, "-R", 2) == 0) {
char save = *end;
*end = 0; /* set a temporary string terminator */
if (lt_dladdsearchdir(p+2))
goto cleanup;
*end = save;
} else
depcount++;
p = end;
} else
p++;
}
if (!depcount) {
ret = 0;
goto cleanup;
}
names = lt_dlmalloc(depcount * sizeof(char*));
if (!names)
goto cleanup;
handles = lt_dlmalloc(depcount * sizeof(lt_dlhandle*));
if (!handles)
goto cleanup;
depcount = 0;
/* now only extract the actual deplibs */
p = deplibs;
while (*p) {
if (!isspace(*p)) {
char *end = p+1;
while (*end && !isspace(*end)) end++;
if (strncmp(p, "-L", 2) != 0 &&
strncmp(p, "-R", 2) != 0) {
char *name;
char save = *end;
*end = 0; /* set a temporary string terminator */
if (strncmp(p, "-l", 2) == 0) {
name = lt_dlmalloc(3+ /* "lib" */
strlen(p+2)+strlen(shlib_ext)+1);
if (name)
sprintf(name, "lib%s%s", p+2, shlib_ext);
} else
name = strdup(p);
if (name)
names[depcount++] = name;
else
goto cleanup_names;
*end = save;
}
p = end;
} else
p++;
}
/* load the deplibs (in reverse order) */
for (i = 0; i < depcount; i++) {
lt_dlhandle handle = lt_dlopen(names[depcount-1-i]);
if (!handle) {
int j;
for (j = 0; j < i; j++)
lt_dlclose(handles[j]);
last_error = deplib_not_found_error;
goto cleanup_names;
}
handles[i] = handle;
}
handle->depcount = depcount;
handle->deplibs = handles;
handles = 0;
ret = 0;
cleanup_names:
for (i = 0; i < depcount; i++)
lt_dlfree(names[i]);
cleanup:
if (names)
lt_dlfree(names);
if (handles)
lt_dlfree(handles);
/* restore the old search path */
if (user_search_path)
lt_dlfree(user_search_path);
user_search_path = save_search_path;
return ret;
1999-01-13 04:42:47 +08:00
}
static int
unload_deplibs(handle)
1999-01-17 19:19:40 +08:00
lt_dlhandle handle;
1999-01-13 04:42:47 +08:00
{
int i;
int errors = 0;
if (!handle->depcount)
return 0;
for (i = 0; i < handle->depcount; i++)
errors += lt_dlclose(handle->deplibs[i]);
return errors;
1999-01-13 04:42:47 +08:00
}
static inline int
trim (dest, str)
char **dest;
const char *str;
{
/* remove the leading and trailing "'" from str
and store the result in dest */
char *tmp;
const char *end = strrchr(str, '\'');
int len = strlen(str);
if (*dest)
lt_dlfree(*dest);
if (len > 3 && str[0] == '\'') {
tmp = (char*) lt_dlmalloc(end - str);
if (!tmp) {
last_error = memory_error;
return 1;
}
strncpy(tmp, &str[1], (end - str) - 1);
tmp[len-3] = '\0';
*dest = tmp;
} else
*dest = 0;
return 0;
}
static inline int
free_vars( dlname, oldname, libdir, deplibs)
char *dlname;
char *oldname;
char *libdir;
char *deplibs;
{
if (dlname)
lt_dlfree(dlname);
if (oldname)
lt_dlfree(oldname);
if (libdir)
lt_dlfree(libdir);
if (deplibs)
lt_dlfree(deplibs);
return 0;
}
1998-11-24 05:26:38 +08:00
lt_dlhandle
1998-12-20 03:30:30 +08:00
lt_dlopen (filename)
const char *filename;
{
lt_dlhandle handle = 0, newhandle;
const char *ext;
1999-01-10 04:05:55 +08:00
const char *saved_error = last_error;
char *canonical = 0, *basename = 0, *dir = 0, *name = 0;
1998-11-24 05:26:38 +08:00
if (!filename) {
handle = (lt_dlhandle) lt_dlmalloc(sizeof(lt_dlhandle_t));
if (!handle) {
last_error = memory_error;
return 0;
}
handle->info.ref_count = 0;
handle->depcount = 0;
handle->deplibs = 0;
newhandle = handle;
if (tryall_dlopen(&newhandle, 0) != 0) {
lt_dlfree(handle);
return 0;
}
goto register_handle;
}
canonical = canonicalize_path (filename);
if (!canonical) {
last_error = memory_error;
if (handle)
lt_dlfree(handle);
return 0;
}
basename = strrchr(canonical, '/');
if (basename) {
basename++;
dir = (char*) lt_dlmalloc(basename - canonical + 1);
if (!dir) {
last_error = memory_error;
handle = 0;
goto cleanup;
}
strncpy(dir, canonical, basename - canonical);
dir[basename - canonical] = '\0';
} else
basename = canonical;
1998-11-24 05:26:38 +08:00
/* check whether we open a libtool module (.la extension) */
1998-12-02 21:05:23 +08:00
ext = strrchr(basename, '.');
1998-11-24 05:26:38 +08:00
if (ext && strcmp(ext, ".la") == 0) {
/* this seems to be a libtool module */
1999-01-13 04:42:47 +08:00
FILE *file;
1998-12-19 06:23:51 +08:00
int i;
char *dlname = 0, *old_name = 0;
char *libdir = 0, *deplibs = 0;
char *line;
int error = 0;
/* if we can't find the installed flag, it is probably an
installed libtool archive, produced with an old version
of libtool */
int installed = 1;
1999-01-13 04:42:47 +08:00
/* extract the module name from the file name */
name = (char*) lt_dlmalloc(ext - basename + 1);
if (!name) {
last_error = memory_error;
handle = 0;
goto cleanup;
1998-12-23 21:28:28 +08:00
}
1999-01-13 04:42:47 +08:00
/* canonicalize the module name */
for (i = 0; i < ext - basename; i++)
if (isalnum((int)(basename[i])))
name[i] = basename[i];
else
name[i] = '_';
name[ext - basename] = '\0';
/* now try to open the .la file */
1999-01-17 19:19:40 +08:00
file = fopen(filename, LTDL_READTEXT_MODE);
if (!file)
last_error = file_not_found_error;
if (!file && !dir) {
1999-01-17 19:19:40 +08:00
/* try other directories */
file = (FILE*) find_file(basename,
user_search_path,
&dir, 0);
1999-01-17 19:19:40 +08:00
if (!file)
file = (FILE*) find_file(basename,
getenv("LTDL_LIBRARY_PATH"),
&dir, 0);
#ifdef LTDL_SHLIBPATH_VAR
1999-01-17 19:19:40 +08:00
if (!file)
file = (FILE*) find_file(basename,
getenv(LTDL_SHLIBPATH_VAR),
&dir, 0);
#endif
#ifdef LTDL_SYSSEARCHPATH
if (!file)
file = (FILE*) find_file(basename,
sys_search_path,
&dir, 0);
#endif
1999-01-17 19:19:40 +08:00
}
1999-01-10 04:05:55 +08:00
if (!file) {
handle = 0;
goto cleanup;
1999-01-10 04:05:55 +08:00
}
line = (char*) lt_dlmalloc(LTDL_FILENAME_MAX);
if (!line) {
fclose(file);
last_error = memory_error;
handle = 0;
goto cleanup;
}
/* read the .la file */
1998-11-24 05:26:38 +08:00
while (!feof(file)) {
if (!fgets(line, LTDL_FILENAME_MAX, file))
1998-11-24 05:26:38 +08:00
break;
if (line[0] == '\n' || line[0] == '#')
continue;
# undef STR_DLNAME
# define STR_DLNAME "dlname="
if (strncmp(line, STR_DLNAME,
sizeof(STR_DLNAME) - 1) == 0)
error = trim(&dlname,
&line[sizeof(STR_DLNAME) - 1]);
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
else
# undef STR_OLD_LIBRARY
# define STR_OLD_LIBRARY "old_library="
if (strncmp(line, STR_OLD_LIBRARY,
sizeof(STR_OLD_LIBRARY) - 1) == 0)
error = trim(&old_name,
&line[sizeof(STR_OLD_LIBRARY) - 1]);
1998-12-23 21:28:28 +08:00
else
# undef STR_LIBDIR
# define STR_LIBDIR "libdir="
if (strncmp(line, STR_LIBDIR,
sizeof(STR_LIBDIR) - 1) == 0)
error = trim(&libdir,
&line[sizeof(STR_LIBDIR) - 1]);
1998-12-23 21:28:28 +08:00
else
# undef STR_DL_DEPLIBS
# define STR_DL_DEPLIBS "dl_dependency_libs="
if (strncmp(line, STR_DL_DEPLIBS,
sizeof(STR_DL_DEPLIBS) - 1) == 0)
error = trim(&deplibs,
&line[sizeof(STR_DL_DEPLIBS) - 1]);
else
if (strcmp(line, "installed=yes\n") == 0)
installed = 1;
else
if (strcmp(line, "installed=no\n") == 0)
installed = 0;
if (error)
break;
1998-11-24 05:26:38 +08:00
}
fclose(file);
lt_dlfree(line);
/* allocate the handle */
handle = (lt_dlhandle) lt_dlmalloc(sizeof(lt_dlhandle_t));
if (!handle || error) {
if (handle)
lt_dlfree(handle);
if (!error)
last_error = memory_error;
free_vars(dlname, old_name, libdir, deplibs);
/* handle is already set to 0 */
goto cleanup;
1999-01-10 04:05:55 +08:00
}
handle->info.ref_count = 0;
if (load_deplibs(handle, deplibs) == 0) {
newhandle = handle;
/* find_module may replace newhandle */
if (find_module(&newhandle, dir, libdir,
dlname, old_name, installed)) {
unload_deplibs(handle);
error = 1;
}
} else
error = 1;
free_vars(dlname, old_name, libdir, deplibs);
if (error) {
lt_dlfree(handle);
handle = 0;
goto cleanup;
1999-01-10 04:05:55 +08:00
}
if (handle != newhandle)
unload_deplibs(handle);
1998-11-24 05:26:38 +08:00
} else {
/* not a libtool module */
handle = (lt_dlhandle) lt_dlmalloc(sizeof(lt_dlhandle_t));
1999-01-10 04:05:55 +08:00
if (!handle) {
last_error = memory_error;
/* handle is already set to 0 */
goto cleanup;
1999-01-10 04:05:55 +08:00
}
handle->info.ref_count = 0;
/* non-libtool modules don't have dependencies */
handle->depcount = 0;
handle->deplibs = 0;
newhandle = handle;
if (tryall_dlopen(&newhandle, filename)
&& (dir
|| (!find_file(basename, user_search_path,
0, &newhandle)
&& !find_file(basename,
getenv("LTDL_LIBRARY_PATH"),
0, &newhandle)
#ifdef LTDL_SHLIBPATH_VAR
&& !find_file(basename,
getenv(LTDL_SHLIBPATH_VAR),
0, &newhandle)
#endif
#ifdef LTDL_SYSSEARCHPATH
&& !find_file(basename, sys_search_path,
0, &newhandle)
#endif
))) {
lt_dlfree(handle);
handle = 0;
goto cleanup;
1998-11-24 05:26:38 +08:00
}
}
register_handle:
if (newhandle != handle) {
lt_dlfree(handle);
handle = newhandle;
1998-11-24 05:26:38 +08:00
}
if (!handle->info.ref_count) {
handle->info.ref_count = 1;
handle->app_private = 0;
handle->info.name = name;
handle->next = handles;
handles = handle;
name = 0; /* don't free this during `cleanup' */
}
last_error = saved_error;
cleanup:
if (dir)
lt_dlfree(dir);
if (name)
lt_dlfree(name);
if (canonical)
lt_dlfree(canonical);
1998-11-24 05:26:38 +08:00
return handle;
}
lt_dlhandle
lt_dlopenext (filename)
const char *filename;
{
lt_dlhandle handle;
char *tmp;
int len;
const char *saved_error = last_error;
if (!filename)
return lt_dlopen(filename);
len = strlen(filename);
if (!len) {
last_error = file_not_found_error;
return 0;
}
/* try the normal file name */
handle = lt_dlopen(filename);
if (handle)
return handle;
/* try "filename.la" */
tmp = (char*) lt_dlmalloc(len+4);
if (!tmp) {
last_error = memory_error;
return 0;
}
strcpy(tmp, filename);
strcat(tmp, ".la");
handle = lt_dlopen(tmp);
if (handle) {
last_error = saved_error;
lt_dlfree(tmp);
return handle;
}
#ifdef LTDL_SHLIB_EXT
/* try "filename.EXT" */
if (strlen(shlib_ext) > 3) {
lt_dlfree(tmp);
tmp = (char*) lt_dlmalloc(len + strlen(shlib_ext) + 1);
if (!tmp) {
last_error = memory_error;
return 0;
}
strcpy(tmp, filename);
} else
tmp[len] = '\0';
strcat(tmp, shlib_ext);
handle = lt_dlopen(tmp);
if (handle) {
last_error = saved_error;
lt_dlfree(tmp);
return handle;
}
#endif
last_error = file_not_found_error;
lt_dlfree(tmp);
return 0;
}
1998-11-24 05:26:38 +08:00
int
1998-12-20 03:30:30 +08:00
lt_dlclose (handle)
lt_dlhandle handle;
1998-11-24 05:26:38 +08:00
{
lt_dlhandle cur, last;
/* check whether the handle is valid */
last = cur = handles;
while (cur && handle != cur) {
last = cur;
cur = cur->next;
}
1999-01-10 04:05:55 +08:00
if (!cur) {
last_error = invalid_handle_error;
return 1;
}
handle->info.ref_count--;
if (!handle->info.ref_count) {
1998-11-24 05:26:38 +08:00
int error;
if (handle != handles)
last->next = handle->next;
else
handles = handle->next;
* ltmain.in (-force-static, force_static): removed * libltdl/Makefile.am (CFLAGS): ditto * libltdl/configure.in: check for memory.h, rindex() and dlpreopening. Fixed NEED_USCORE caching policy. * libltdl/ltdl.h (lt_dlsym): make the name argument const * libltdl/ltdl.c (types): new variable: head of list of available dlopening mechanisms (lt_dltype_t): interface of a dlopening mechanism, with pointers to functions for init, exit, open, close and sym (lt_dlhandle_t): added pointer to interface type (strdup): don't name it strdup; it can be troublesome (strrchr): ditto; use rindex if available (LIBTOOL_STATIC): check HAVE_DLPREOPEN instead, and move to the end of the file, so that it becomes the header of the list (all): renamed all interface-implementation functions, to avoid name clashes, and created lt_dltype_t nodes for all of them (lt_dlinit): initialize all available interfaces; remove those that fail from the list. Return failure only if no interfaces could be initialized. (lt_dlexit): return number of failures (tryall_dlopen): try to open the library with all available interfaces (lt_dlopen): use tryall_dlopen; increased size of fixed buffers. We should probably make these bound-checked or dynamically allocated for the final release! Fix bug when filename did not contain slashes; should we check for `\\' too? Try old_library if everything else fails. (lt_dlclose): use the interface type for closing (lt_dlsym): make `symbol' const, use interface type for looking up * mdemo/Makefile.am: moved mdemo/modules/* back into mdemo (SUBDIRS): removed (libfoo2_la_LDFLAGS): added -static; nice test. However, since it causes -lm to linked into hell*, it causes tests that should fail to pass (noinst_HEADERS): no need to install foo.h * mdemo/configure.in: remove modules/Makefile tests/mdemo-exec.test: updated accordingly
1998-12-16 13:42:23 +08:00
error = handle->type->lib_close(handle);
1999-01-13 04:42:47 +08:00
error += unload_deplibs(handle);
if (handle->info.filename)
lt_dlfree(handle->info.filename);
if (handle->info.name)
lt_dlfree(handle->info.name);
lt_dlfree(handle);
1998-11-24 05:26:38 +08:00
return error;
}
return 0;
}
1998-12-19 06:23:51 +08:00
lt_ptr_t
1998-12-20 03:30:30 +08:00
lt_dlsym (handle, symbol)
lt_dlhandle handle;
const char *symbol;
{
1999-01-15 00:31:23 +08:00
int lensym;
1999-01-17 19:19:40 +08:00
char lsym[LTDL_SYMBOL_LENGTH];
1999-01-13 04:42:47 +08:00
char *sym;
1998-12-19 06:23:51 +08:00
lt_ptr_t address;
1998-11-24 05:26:38 +08:00
1999-01-13 04:42:47 +08:00
if (!handle) {
last_error = invalid_handle_error;
return 0;
}
1999-01-14 05:39:14 +08:00
if (!symbol) {
last_error = symbol_error;
return 0;
}
1999-01-13 04:42:47 +08:00
lensym = strlen(symbol);
1999-01-15 00:31:23 +08:00
if (handle->type->sym_prefix)
lensym += strlen(handle->type->sym_prefix);
if (handle->info.name)
lensym += strlen(handle->info.name);
1999-01-17 19:19:40 +08:00
if (lensym + LTDL_SYMBOL_OVERHEAD < LTDL_SYMBOL_LENGTH)
1999-01-13 04:42:47 +08:00
sym = lsym;
else
sym = (char*) lt_dlmalloc(lensym + LTDL_SYMBOL_OVERHEAD + 1);
1999-01-13 04:42:47 +08:00
if (!sym) {
1999-01-10 04:05:55 +08:00
last_error = buffer_overflow_error;
return 0;
}
if (handle->info.name) {
const char *saved_error = last_error;
1999-01-13 04:42:47 +08:00
/* this is a libtool module */
1999-01-15 00:31:23 +08:00
if (handle->type->sym_prefix) {
strcpy(sym, handle->type->sym_prefix);
strcat(sym, handle->info.name);
1999-01-17 19:19:40 +08:00
} else
strcpy(sym, handle->info.name);
1999-01-13 04:42:47 +08:00
strcat(sym, "_LTX_");
strcat(sym, symbol);
/* try "modulename_LTX_symbol" */
address = handle->type->find_sym(handle, sym);
if (address) {
if (sym != lsym)
lt_dlfree(sym);
1999-01-13 04:42:47 +08:00
return address;
}
last_error = saved_error;
1998-11-24 05:26:38 +08:00
}
/* otherwise try "symbol" */
1999-01-15 00:31:23 +08:00
if (handle->type->sym_prefix) {
strcpy(sym, handle->type->sym_prefix);
strcat(sym, symbol);
1999-01-17 19:19:40 +08:00
} else
strcpy(sym, symbol);
address = handle->type->find_sym(handle, sym);
if (sym != lsym)
lt_dlfree(sym);
return address;
}
const char *
lt_dlerror LTDL_PARAMS((void))
{
1999-01-10 04:05:55 +08:00
const char *error = last_error;
last_error = 0;
return error;
}
1999-01-15 00:31:23 +08:00
1999-01-17 19:19:40 +08:00
int
lt_dladdsearchdir (search_dir)
const char *search_dir;
{
if (!search_dir || !strlen(search_dir))
1999-01-17 19:19:40 +08:00
return 0;
if (!user_search_path) {
user_search_path = strdup(search_dir);
if (!user_search_path) {
last_error = memory_error;
return 1;
}
} else {
char *new_search_path = (char*)
lt_dlmalloc(strlen(user_search_path) +
strlen(search_dir) + 2); /* ':' + '\0' == 2 */
if (!new_search_path) {
last_error = memory_error;
return 1;
}
sprintf (new_search_path, "%s%c%s", user_search_path,
LTDL_PATHSEP_CHAR, search_dir);
lt_dlfree(user_search_path);
user_search_path = new_search_path;
}
1999-01-17 19:19:40 +08:00
return 0;
}
int
lt_dlsetsearchpath (search_path)
1999-01-15 00:31:23 +08:00
const char *search_path;
{
if (user_search_path)
lt_dlfree(user_search_path);
user_search_path = 0; /* reset the search path */
if (!search_path || !strlen(search_path))
1999-01-17 19:19:40 +08:00
return 0;
user_search_path = strdup(search_path);
if (!user_search_path)
1999-01-17 19:19:40 +08:00
return 1;
return 0;
}
const char *
lt_dlgetsearchpath LTDL_PARAMS((void))
1999-01-17 19:19:40 +08:00
{
return user_search_path;
1999-01-15 00:31:23 +08:00
}
int
lt_dlsetdata (handle, data)
lt_dlhandle handle;
lt_ptr_t data;
{
if (!handle) {
last_error = invalid_handle_error;
return 1;
}
handle->app_private = data;
return 0;
}
lt_ptr_t
lt_dlgetdata (handle)
lt_dlhandle handle;
{
if (!handle) {
last_error = invalid_handle_error;
return 0;
}
return handle->app_private;
}
const lt_dlinfo *
lt_dlgetinfo (handle)
lt_dlhandle handle;
{
if (!handle) {
last_error = invalid_handle_error;
return 0;
}
return &(handle->info);
}
int
lt_dlforeach (func, data)
int (*func) LTDL_PARAMS((lt_dlhandle handle, lt_ptr_t data));
lt_ptr_t data;
{
lt_dlhandle cur = handles;
while (cur) {
lt_dlhandle tmp = cur;
cur = cur->next;
if (func(tmp, data))
return 1;
}
return 0;
}