mirror of
git://git.savannah.gnu.org/libtool.git
synced 2025-02-17 15:10:02 +08:00
portability enhancements
This commit is contained in:
parent
3ce33a45f6
commit
9817e05d7b
@ -7,7 +7,8 @@ AM_PROG_LIBTOOL
|
||||
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(malloc.h dlfcn.h dl.h)
|
||||
AC_CHECK_FUNCS(strdup)
|
||||
AC_CHECK_HEADERS(string.h strings.h, break)
|
||||
AC_CHECK_FUNCS(strdup strrchr)
|
||||
|
||||
LIBADD_DL=
|
||||
AC_CHECK_FUNCS(dlopen, AC_DEFINE(HAVE_LIBDL),
|
||||
@ -22,17 +23,17 @@ AC_SUBST(LIBADD_DL)
|
||||
AC_MSG_CHECKING(for underscore before symbols)
|
||||
AC_CACHE_VAL(libltdl_cv_uscore,[
|
||||
echo "main(){int i=1;} fnord(){int i=23; int ltuae=42;}" > conftest.c
|
||||
${CC} conftest.c > /dev/null
|
||||
if (nm a.out | grep _fnord) > /dev/null; then
|
||||
${CC} -c conftest.c > /dev/null
|
||||
if (nm conftest.$ac_objext | grep _fnord) > /dev/null; then
|
||||
libltdl_cv_uscore=yes
|
||||
else
|
||||
libltdl_cv_uscore=no
|
||||
fi])
|
||||
AC_MSG_RESULT($libltdl_cv_uscore)
|
||||
rm -f conftest.c a.out
|
||||
rm -f conftest*
|
||||
|
||||
if test $libltdl_cv_uscore = yes; then
|
||||
if test $ac_cv_func_dlopen = yes -o $ac_cv_lib_dl_dlopen = yes ; then
|
||||
if test $ac_cv_func_dlopen = yes || test $ac_cv_lib_dl_dlopen = yes ; then
|
||||
AC_MSG_CHECKING(whether we have to add an underscore for dlsym)
|
||||
AC_CACHE_VAL(libltdl_cv_need_uscore,AC_TRY_RUN([
|
||||
#include <dlfcn.h>
|
||||
@ -42,7 +43,8 @@ main() { void *self, *ptr1, *ptr2; self=dlopen(NULL,RTLD_LAZY);
|
||||
if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord");
|
||||
if(ptr1 && !ptr2) exit(0); } exit(1); }
|
||||
], libltdl_cv_need_uscore=no,
|
||||
[libltdl_cv_need_uscore=yes AC_DEFINE(NEED_USCORE)],
|
||||
[libltdl_cv_need_uscore=yes
|
||||
AC_DEFINE(NEED_USCORE)],
|
||||
libltdl_cv_need_uscore=no))
|
||||
|
||||
AC_MSG_RESULT($libltdl_cv_need_uscore)
|
||||
|
@ -25,12 +25,33 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct lt_dlhandle_t {
|
||||
struct lt_dlhandle_t *next;
|
||||
char *filename; /* file name */
|
||||
char *name; /* module name */
|
||||
int usage; /* usage */
|
||||
__ptr_t handle; /* system handle */
|
||||
__ptr_t sys; /* system specific data */
|
||||
} lt_dlhandle_t;
|
||||
|
||||
static int sys_dlinit __P((void));
|
||||
static int sys_dlexit __P((void));
|
||||
static int sys_dlopen __P((lt_dlhandle handle, const char *filename));
|
||||
static int sys_dlclose __P((lt_dlhandle handle));
|
||||
static __ptr_t sys_dlsym __P((lt_dlhandle handle, char *symbol));
|
||||
static void trim __P((char *dest, const char *s));
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
|
||||
static char *
|
||||
strdup(const char *str)
|
||||
strdup(str)
|
||||
const char *str;
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
@ -44,14 +65,27 @@ strdup(const char *str)
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct lt_dlhandle_t {
|
||||
struct lt_dlhandle_t *next;
|
||||
char *filename; /* file name */
|
||||
char *name; /* module name */
|
||||
int usage; /* usage */
|
||||
void *handle; /* system handle */
|
||||
void *sys; /* system specific data */
|
||||
} lt_dlhandle_t;
|
||||
#ifndef HAVE_STRRCHR
|
||||
|
||||
static char*
|
||||
strrchr(str, ch)
|
||||
const char *str;
|
||||
int ch;
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = str; p != '\0'; p++)
|
||||
/*NOWORK*/;
|
||||
|
||||
while (*p != (char)ch && p >= str)
|
||||
{
|
||||
p--;
|
||||
}
|
||||
|
||||
return (*p == (char)ch) ? p : NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef STATIC
|
||||
|
||||
@ -60,7 +94,7 @@ typedef struct lt_dlhandle_t {
|
||||
struct dld_symlist
|
||||
{
|
||||
char *name;
|
||||
void *address;
|
||||
__ptr_t address;
|
||||
};
|
||||
|
||||
extern struct dld_symlist dld_preloaded_symbols[];
|
||||
@ -99,7 +133,7 @@ sys_dlclose (handle) lt_dlhandle handle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
static __ptr_t
|
||||
sys_dlsym (handle, symbol) lt_dlhandle handle; char *symbol;
|
||||
{
|
||||
struct dld_symlist *s = (struct dld_symlist*)(handle->handle);
|
||||
@ -159,7 +193,7 @@ sys_dlclose (handle) lt_dlhandle handle;
|
||||
return dlclose(handle->handle);
|
||||
}
|
||||
|
||||
static void *
|
||||
static __ptr_t
|
||||
sys_dlsym (handle, symbol) lt_dlhandle handle; char *symbol;
|
||||
{
|
||||
return dlsym(handle->handle, symbol);
|
||||
@ -202,7 +236,7 @@ sys_dlclose (handle) lt_dlhandle handle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
static __ptr_t
|
||||
sys_dlsym (handle, symbol) lt_dlhandle handle; char *symbol;
|
||||
{
|
||||
int status, i;
|
||||
@ -249,7 +283,7 @@ sys_dlclose (handle) lt_dlhandle handle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
static __ptr_t
|
||||
sys_dlsym (handle, symbol) lt_dlhandle handle; char *symbol;
|
||||
{
|
||||
return dld_get_func(symbol);
|
||||
@ -288,7 +322,7 @@ sys_dlclose (handle) lt_dlhandle handle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
static __ptr_t
|
||||
sys_dlsym (handle, symbol) lt_dlhandle handle; char *symbol;
|
||||
{
|
||||
return GetProcAddress(handle->handle, symbol);
|
||||
@ -322,7 +356,7 @@ sys_dlclose (handle) lt_dlhandle handle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
static __ptr_t
|
||||
sys_dlsym (handle, symbol) lt_dlhandle handle; char *symbol;
|
||||
{
|
||||
return 0;
|
||||
@ -374,9 +408,9 @@ lt_dlexit ()
|
||||
}
|
||||
|
||||
static void
|
||||
trim (char *dest, const char *s)
|
||||
trim (dest, s) char *dest; const char *s;
|
||||
{
|
||||
char *i = rindex(s, '\'');
|
||||
char *i = strrchr(s, '\'');
|
||||
int len = strlen(s);
|
||||
|
||||
if (len > 3 && s[0] == '\'') {
|
||||
@ -406,20 +440,20 @@ lt_dlopen (filename) const char *filename;
|
||||
handle = (lt_dlhandle) malloc(sizeof(lt_dlhandle_t));
|
||||
if (!handle)
|
||||
return 0;
|
||||
basename = rindex(filename, '/'); /* FIXME: portable? */
|
||||
basename = strrchr(filename, '/');
|
||||
if (basename)
|
||||
basename++;
|
||||
strncpy(dir, filename, basename - filename);
|
||||
dir[basename - filename] = '\0';
|
||||
/* check whether we open a libtool module (.la extension) */
|
||||
ext = rindex(basename, '.');
|
||||
ext = strrchr(basename, '.');
|
||||
if (ext && strcmp(ext, ".la") == 0) {
|
||||
char dlname[256], libdir[512], deps[512];
|
||||
char fullname[512];
|
||||
|
||||
file = fopen(filename, "r"); /* FIXME: portable? */
|
||||
if (!file) {
|
||||
free(handle);
|
||||
free(handle);
|
||||
return 0;
|
||||
}
|
||||
while (!feof(file)) {
|
||||
@ -520,11 +554,11 @@ lt_dlclose (handle) lt_dlhandle handle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
__ptr_t
|
||||
lt_dlsym (handle, symbol) lt_dlhandle handle; char *symbol;
|
||||
{
|
||||
char sym[128];
|
||||
void *address;
|
||||
__ptr_t address;
|
||||
|
||||
if (handle->name) { /* libtool module */
|
||||
#ifdef NEED_USCORE
|
||||
|
@ -38,16 +38,19 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
that don't understand ANSI C prototypes still work, and ANSI C
|
||||
compilers can issue warnings about type mismatches. */
|
||||
#undef __P
|
||||
#undef __ptr_t
|
||||
#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus)
|
||||
# define __P(protos) protos
|
||||
# define __ptr_t void*
|
||||
#else
|
||||
# define __P(protos) ()
|
||||
# define __ptr_t char*
|
||||
#endif
|
||||
|
||||
#ifdef _LTDL_COMPILE_
|
||||
typedef struct lt_dlhandle_t *lt_dlhandle;
|
||||
#else
|
||||
typedef void *lt_dlhandle;
|
||||
typedef __ptr_t lt_dlhandle;
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
@ -55,7 +58,7 @@ int lt_dlinit __P((void));
|
||||
int lt_dlexit __P((void));
|
||||
lt_dlhandle lt_dlopen __P((const char *filename));
|
||||
int lt_dlclose __P((lt_dlhandle handle));
|
||||
void *lt_dlsym __P((lt_dlhandle handle, char *name));
|
||||
__ptr_t lt_dlsym __P((lt_dlhandle handle, char *name));
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_LTDL_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user