65 |
# include <errno.h> |
# include <errno.h> |
66 |
#endif |
#endif |
67 |
|
|
68 |
#if HAVE_DIRENT_H |
|
69 |
|
#ifndef __WINDOWS__ |
70 |
|
# ifdef __WIN32__ |
71 |
|
# define __WINDOWS__ |
72 |
|
# endif |
73 |
|
#endif |
74 |
|
|
75 |
|
|
76 |
|
#undef LT_USE_POSIX_DIRENT |
77 |
|
#ifdef HAVE_CLOSEDIR |
78 |
|
# ifdef HAVE_OPENDIR |
79 |
|
# ifdef HAVE_READDIR |
80 |
|
# ifdef HAVE_DIRENT_H |
81 |
|
# define LT_USE_POSIX_DIRENT |
82 |
|
# endif /* HAVE_DIRENT_H */ |
83 |
|
# endif /* HAVE_READDIR */ |
84 |
|
# endif /* HAVE_OPENDIR */ |
85 |
|
#endif /* HAVE_CLOSEDIR */ |
86 |
|
|
87 |
|
|
88 |
|
#undef LT_USE_WINDOWS_DIRENT_EMULATION |
89 |
|
#ifndef LT_USE_POSIX_DIRENT |
90 |
|
# ifdef __WINDOWS__ |
91 |
|
# define LT_USE_WINDOWS_DIRENT_EMULATION |
92 |
|
# endif /* __WINDOWS__ */ |
93 |
|
#endif /* LT_USE_POSIX_DIRENT */ |
94 |
|
|
95 |
|
|
96 |
|
#ifdef LT_USE_POSIX_DIRENT |
97 |
# include <dirent.h> |
# include <dirent.h> |
98 |
# define LT_D_NAMLEN(dirent) (strlen((dirent)->d_name)) |
# define LT_D_NAMLEN(dirent) (strlen((dirent)->d_name)) |
99 |
#else |
#else |
100 |
# define dirent direct |
# ifdef LT_USE_WINDOWS_DIRENT_EMULATION |
101 |
# define LT_D_NAMLEN(dirent) ((dirent)->d_namlen) |
# define LT_D_NAMLEN(dirent) (strlen((dirent)->d_name)) |
102 |
# if HAVE_SYS_NDIR_H |
# else |
103 |
# include <sys/ndir.h> |
# define dirent direct |
104 |
# endif |
# define LT_D_NAMLEN(dirent) ((dirent)->d_namlen) |
105 |
# if HAVE_SYS_DIR_H |
# if HAVE_SYS_NDIR_H |
106 |
# include <sys/dir.h> |
# include <sys/ndir.h> |
107 |
# endif |
# endif |
108 |
# if HAVE_NDIR_H |
# if HAVE_SYS_DIR_H |
109 |
# include <ndir.h> |
# include <sys/dir.h> |
110 |
|
# endif |
111 |
|
# if HAVE_NDIR_H |
112 |
|
# include <ndir.h> |
113 |
|
# endif |
114 |
# endif |
# endif |
115 |
#endif |
#endif |
116 |
|
|
152 |
# define LT_READTEXT_MODE "r" |
# define LT_READTEXT_MODE "r" |
153 |
#endif |
#endif |
154 |
|
|
155 |
|
#ifdef LT_USE_WINDOWS_DIRENT_EMULATION |
156 |
|
|
157 |
|
#include <windows.h> |
158 |
|
|
159 |
|
#define dirent lt_dirent |
160 |
|
#define DIR lt_DIR |
161 |
|
|
162 |
|
struct dirent |
163 |
|
{ |
164 |
|
char d_name[2048]; |
165 |
|
int d_namlen; |
166 |
|
}; |
167 |
|
|
168 |
|
typedef struct _DIR |
169 |
|
{ |
170 |
|
HANDLE hSearch; |
171 |
|
WIN32_FIND_DATA Win32FindData; |
172 |
|
BOOL firsttime; |
173 |
|
struct dirent file_info; |
174 |
|
} DIR; |
175 |
|
|
176 |
|
#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ |
177 |
|
|
178 |
|
|
179 |
/* --- MANIFEST CONSTANTS --- */ |
/* --- MANIFEST CONSTANTS --- */ |
213 |
static lt_ptr lt_emalloc LT_PARAMS((size_t size)); |
static lt_ptr lt_emalloc LT_PARAMS((size_t size)); |
214 |
static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size)); |
static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size)); |
215 |
|
|
216 |
|
/* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */ |
217 |
#define rpl_realloc realloc |
#define rpl_realloc realloc |
218 |
|
|
219 |
/* These are the pointers that can be changed by the caller: */ |
/* These are the pointers that can be changed by the caller: */ |
265 |
strdup(str) |
strdup(str) |
266 |
const char *str; |
const char *str; |
267 |
{ |
{ |
268 |
char *tmp = NULL; |
char *tmp = 0; |
269 |
|
|
270 |
if (str) |
if (str) |
271 |
{ |
{ |
294 |
{ |
{ |
295 |
if (str1 == str2) |
if (str1 == str2) |
296 |
return 0; |
return 0; |
297 |
if (str1 == NULL) |
if (str1 == 0) |
298 |
return -1; |
return -1; |
299 |
if (str2 == NULL) |
if (str2 == 0) |
300 |
return 1; |
return 1; |
301 |
|
|
302 |
for (;*str1 && *str2; ++str1, ++str2) |
for (;*str1 && *str2; ++str1, ++str2) |
350 |
const char *str; |
const char *str; |
351 |
int ch; |
int ch; |
352 |
{ |
{ |
353 |
const char *p, *q = NULL; |
const char *p, *q = 0; |
354 |
|
|
355 |
for (p = str; *p != LT_EOS_CHAR; ++p) |
for (p = str; *p != LT_EOS_CHAR; ++p) |
356 |
{ |
{ |
427 |
|
|
428 |
#endif /* !HAVE_MEMMOVE */ |
#endif /* !HAVE_MEMMOVE */ |
429 |
|
|
430 |
|
#ifdef LT_USE_WINDOWS_DIRENT_EMULATION |
431 |
|
|
432 |
|
static void closedir LT_PARAMS((DIR *entry)); |
433 |
|
|
434 |
|
static void |
435 |
|
closedir(entry) |
436 |
|
DIR *entry; |
437 |
|
{ |
438 |
|
assert(entry != (DIR *) NULL); |
439 |
|
FindClose(entry->hSearch); |
440 |
|
lt_dlfree((lt_ptr)entry); |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
|
static DIR * opendir LT_PARAMS((const char *path)); |
445 |
|
|
446 |
|
static DIR* |
447 |
|
opendir (path) |
448 |
|
const char *path; |
449 |
|
{ |
450 |
|
char file_specification[LT_FILENAME_MAX]; |
451 |
|
DIR *entry; |
452 |
|
|
453 |
|
assert(path != (char *) NULL); |
454 |
|
(void) strncpy(file_specification,path,LT_FILENAME_MAX-1); |
455 |
|
(void) strcat(file_specification,"\\"); |
456 |
|
entry = LT_DLMALLOC (DIR,sizeof(DIR)); |
457 |
|
if (entry != (DIR *) 0) |
458 |
|
{ |
459 |
|
entry->firsttime = TRUE; |
460 |
|
entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); |
461 |
|
} |
462 |
|
if (entry->hSearch == INVALID_HANDLE_VALUE) |
463 |
|
{ |
464 |
|
(void) strcat(file_specification,"\\*.*"); |
465 |
|
entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); |
466 |
|
if (entry->hSearch == INVALID_HANDLE_VALUE) |
467 |
|
{ |
468 |
|
LT_DLFREE (entry); |
469 |
|
return (DIR *) 0; |
470 |
|
} |
471 |
|
} |
472 |
|
return(entry); |
473 |
|
} |
474 |
|
|
475 |
|
|
476 |
|
static struct dirent *readdir LT_PARAMS((DIR *entry)); |
477 |
|
|
478 |
|
static struct dirent *readdir(entry) |
479 |
|
DIR *entry; |
480 |
|
{ |
481 |
|
int |
482 |
|
status; |
483 |
|
|
484 |
|
if (entry == (DIR *) 0) |
485 |
|
return((struct dirent *) 0); |
486 |
|
if (!entry->firsttime) |
487 |
|
{ |
488 |
|
status = FindNextFile(entry->hSearch,&entry->Win32FindData); |
489 |
|
if (status == 0) |
490 |
|
return((struct dirent *) 0); |
491 |
|
} |
492 |
|
entry->firsttime = FALSE; |
493 |
|
(void) strncpy(entry->file_info.d_name,entry->Win32FindData.cFileName, |
494 |
|
LT_FILENAME_MAX-1); |
495 |
|
entry->file_info.d_namlen = strlen(entry->file_info.d_name); |
496 |
|
return(&entry->file_info); |
497 |
|
} |
498 |
|
|
499 |
|
#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ |
500 |
|
|
501 |
/* According to Alexandre Oliva <oliva@lsd.ic.unicamp.br>, |
/* According to Alexandre Oliva <oliva@lsd.ic.unicamp.br>, |
502 |
``realloc is not entirely portable'' |
``realloc is not entirely portable'' |
505 |
Instead implement our own version (with known boundary conditions) |
Instead implement our own version (with known boundary conditions) |
506 |
using lt_dlmalloc and lt_dlfree. */ |
using lt_dlmalloc and lt_dlfree. */ |
507 |
|
|
508 |
|
/* #undef realloc |
509 |
|
#define realloc rpl_realloc |
510 |
|
*/ |
511 |
#if 0 |
#if 0 |
|
|
|
512 |
/* You can't (re)define realloc unless you also (re)define malloc. |
/* You can't (re)define realloc unless you also (re)define malloc. |
513 |
Right now, this code uses the size of the *destination* to decide |
Right now, this code uses the size of the *destination* to decide |
514 |
how much to copy. That's not right, but you can't know the size |
how much to copy. That's not right, but you can't know the size |
523 |
if (size == 0) |
if (size == 0) |
524 |
{ |
{ |
525 |
/* For zero or less bytes, free the original memory */ |
/* For zero or less bytes, free the original memory */ |
526 |
if (ptr != NULL) |
if (ptr != 0) |
527 |
{ |
{ |
528 |
lt_dlfree (ptr); |
lt_dlfree (ptr); |
529 |
} |
} |
530 |
|
|
531 |
return (lt_ptr) 0; |
return (lt_ptr) 0; |
532 |
} |
} |
533 |
else if (ptr == NULL) |
else if (ptr == 0) |
534 |
{ |
{ |
535 |
/* Allow reallocation of a NULL pointer. */ |
/* Allow reallocation of a NULL pointer. */ |
536 |
return lt_dlmalloc (size); |
return lt_dlmalloc (size); |
551 |
return mem; |
return mem; |
552 |
} |
} |
553 |
} |
} |
|
|
|
554 |
#endif |
#endif |
555 |
|
|
556 |
|
|
610 |
size_t *pargz_len; |
size_t *pargz_len; |
611 |
{ |
{ |
612 |
size_t argz_len; |
size_t argz_len; |
613 |
char *argz = NULL; |
char *argz = 0; |
614 |
|
|
615 |
assert (str); |
assert (str); |
616 |
assert (pargz); |
assert (pargz); |
891 |
|
|
892 |
/* The mutex functions stored here are global, and are necessarily the |
/* The mutex functions stored here are global, and are necessarily the |
893 |
same for all threads that wish to share access to libltdl. */ |
same for all threads that wish to share access to libltdl. */ |
894 |
static lt_dlmutex_lock *lt_dlmutex_lock_func = NULL; |
static lt_dlmutex_lock *lt_dlmutex_lock_func = 0; |
895 |
static lt_dlmutex_unlock *lt_dlmutex_unlock_func = NULL; |
static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0; |
896 |
static lt_dlmutex_seterror *lt_dlmutex_seterror_func = NULL; |
static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0; |
897 |
static lt_dlmutex_geterror *lt_dlmutex_geterror_func = NULL; |
static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0; |
898 |
static const char *lt_dllast_error = NULL; |
static const char *lt_dllast_error = 0; |
899 |
|
|
900 |
|
|
901 |
/* Either set or reset the mutex functions. Either all the arguments must |
/* Either set or reset the mutex functions. Either all the arguments must |
943 |
|
|
944 |
/* --- ERROR HANDLING --- */ |
/* --- ERROR HANDLING --- */ |
945 |
|
|
946 |
static const char **user_error_strings = NULL; |
|
947 |
|
static const char **user_error_strings = 0; |
948 |
static int errorcount = LT_ERROR_MAX; |
static int errorcount = LT_ERROR_MAX; |
949 |
|
|
950 |
int |
int |
953 |
{ |
{ |
954 |
int errindex = 0; |
int errindex = 0; |
955 |
int result = -1; |
int result = -1; |
956 |
const char **temp = NULL; |
const char **temp = (const char **) 0; |
957 |
|
|
958 |
assert (diagnostic); |
assert (diagnostic); |
959 |
|
|
1040 |
/* --- DLOPEN() INTERFACE LOADER --- */ |
/* --- DLOPEN() INTERFACE LOADER --- */ |
1041 |
|
|
1042 |
|
|
1043 |
/* The Cygwin dlopen implementation prints a spurious error message to |
#if HAVE_LIBDL |
|
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__) |
|
1044 |
|
|
1045 |
/* dynamic linking with dlopen/dlsym */ |
/* dynamic linking with dlopen/dlsym */ |
1046 |
|
|
1261 |
lt_module module; |
lt_module module; |
1262 |
const char *symbol; |
const char *symbol; |
1263 |
{ |
{ |
1264 |
lt_ptr address = NULL; |
lt_ptr address = 0; |
1265 |
|
|
1266 |
/* sys_shl_open should never return a NULL module handle */ |
/* sys_shl_open should never return a NULL module handle */ |
1267 |
if (module == (lt_module) 0) |
if (module == (lt_module) 0) |
1305 |
const char *filename; |
const char *filename; |
1306 |
{ |
{ |
1307 |
lt_dlhandle cur; |
lt_dlhandle cur; |
1308 |
lt_module module = NULL; |
lt_module module = 0; |
1309 |
const char *errormsg = NULL; |
const char *errormsg = 0; |
1310 |
char *searchname = NULL; |
char *searchname = 0; |
1311 |
char *ext; |
char *ext; |
1312 |
char self_name_buf[MAX_PATH]; |
char self_name_buf[MAX_PATH]; |
1313 |
|
|
1314 |
if (!filename) |
if (!filename) |
1315 |
{ |
{ |
1316 |
/* Get the name of main module */ |
/* Get the name of main module */ |
1317 |
*self_name_buf = '\0'; |
*self_name_buf = 0; |
1318 |
GetModuleFileName (NULL, self_name_buf, sizeof (self_name_buf)); |
GetModuleFileName (NULL, self_name_buf, sizeof (self_name_buf)); |
1319 |
filename = ext = self_name_buf; |
filename = ext = self_name_buf; |
1320 |
} |
} |
1364 |
{ |
{ |
1365 |
if (!cur->module) |
if (!cur->module) |
1366 |
{ |
{ |
1367 |
cur = NULL; |
cur = 0; |
1368 |
break; |
break; |
1369 |
} |
} |
1370 |
|
|
1380 |
if (cur || !module) |
if (cur || !module) |
1381 |
{ |
{ |
1382 |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); |
1383 |
module = NULL; |
module = 0; |
1384 |
} |
} |
1385 |
|
|
1386 |
return module; |
return module; |
1486 |
lt_module module; |
lt_module module; |
1487 |
const char *symbol; |
const char *symbol; |
1488 |
{ |
{ |
1489 |
lt_ptr address = NULL; |
lt_ptr address = 0; |
1490 |
image_id image = (image_id) module; |
image_id image = (image_id) module; |
1491 |
|
|
1492 |
if (get_image_symbol (image, symbol, B_SYMBOL_TYPE_ANY, address) != B_OK) |
if (get_image_symbol (image, symbol, B_SYMBOL_TYPE_ANY, address) != B_OK) |
1493 |
{ |
{ |
1494 |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); |
1495 |
address = NULL; |
address = 0; |
1496 |
} |
} |
1497 |
|
|
1498 |
return address; |
return address; |
1529 |
{ |
{ |
1530 |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); |
1531 |
LT_DLFREE (module); |
LT_DLFREE (module); |
1532 |
module = NULL; |
module = 0; |
1533 |
} |
} |
1534 |
|
|
1535 |
return module; |
return module; |
1577 |
|
|
1578 |
#endif /* HAVE_DLD */ |
#endif /* HAVE_DLD */ |
1579 |
|
|
1580 |
|
/* --- DYLD() MACOSX/DARWIN INTERFACE LOADER --- */ |
1581 |
|
#if HAVE_DYLD |
1582 |
|
|
1583 |
|
|
1584 |
|
#if HAVE_MACH_O_DYLD_H |
1585 |
|
# include <mach-o/dyld.h> |
1586 |
|
#endif |
1587 |
|
#include <mach-o/getsect.h> |
1588 |
|
|
1589 |
|
/* We have to put some stuff here that isn't in older dyld.h files */ |
1590 |
|
#ifndef ENUM_DYLD_BOOL |
1591 |
|
# define ENUM_DYLD_BOOL |
1592 |
|
# undef FALSE |
1593 |
|
# undef TRUE |
1594 |
|
enum DYLD_BOOL { |
1595 |
|
FALSE, |
1596 |
|
TRUE |
1597 |
|
}; |
1598 |
|
#endif |
1599 |
|
#ifndef LC_REQ_DYLD |
1600 |
|
# define LC_REQ_DYLD 0x80000000 |
1601 |
|
#endif |
1602 |
|
#ifndef LC_LOAD_WEAK_DYLIB |
1603 |
|
# define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) |
1604 |
|
#endif |
1605 |
|
static const struct mach_header * (*ltdl_NSAddImage)(const char *image_name, unsigned long options) = 0; |
1606 |
|
static NSSymbol (*ltdl_NSLookupSymbolInImage)(const struct mach_header *image,const char *symbolName, unsigned long options) = 0; |
1607 |
|
static enum DYLD_BOOL (*ltdl_NSIsSymbolNameDefinedInImage)(const struct mach_header *image, const char *symbolName) = 0; |
1608 |
|
static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0; |
1609 |
|
|
1610 |
|
#ifndef NSADDIMAGE_OPTION_NONE |
1611 |
|
#define NSADDIMAGE_OPTION_NONE 0x0 |
1612 |
|
#endif |
1613 |
|
#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR |
1614 |
|
#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1 |
1615 |
|
#endif |
1616 |
|
#ifndef NSADDIMAGE_OPTION_WITH_SEARCHING |
1617 |
|
#define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2 |
1618 |
|
#endif |
1619 |
|
#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
1620 |
|
#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4 |
1621 |
|
#endif |
1622 |
|
#ifndef NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME |
1623 |
|
#define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME 0x8 |
1624 |
|
#endif |
1625 |
|
#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
1626 |
|
#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0 |
1627 |
|
#endif |
1628 |
|
#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
1629 |
|
#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1 |
1630 |
|
#endif |
1631 |
|
#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY |
1632 |
|
#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY 0x2 |
1633 |
|
#endif |
1634 |
|
#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR |
1635 |
|
#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4 |
1636 |
|
#endif |
1637 |
|
|
1638 |
|
|
1639 |
|
static const char * |
1640 |
|
lt_int_dyld_error(othererror) |
1641 |
|
char* othererror; |
1642 |
|
{ |
1643 |
|
/* return the dyld error string, or the passed in error string if none */ |
1644 |
|
NSLinkEditErrors ler; |
1645 |
|
int lerno; |
1646 |
|
const char *errstr; |
1647 |
|
const char *file; |
1648 |
|
NSLinkEditError(&ler,&lerno,&file,&errstr); |
1649 |
|
if (!errstr || !strlen(errstr)) errstr = othererror; |
1650 |
|
return errstr; |
1651 |
|
} |
1652 |
|
|
1653 |
|
static const struct mach_header * |
1654 |
|
lt_int_dyld_get_mach_header_from_nsmodule(module) |
1655 |
|
NSModule module; |
1656 |
|
{ |
1657 |
|
/* There should probably be an apple dyld api for this */ |
1658 |
|
int i=_dyld_image_count(); |
1659 |
|
int j; |
1660 |
|
const char *modname=NSNameOfModule(module); |
1661 |
|
const struct mach_header *mh=NULL; |
1662 |
|
if (!modname) return NULL; |
1663 |
|
for (j = 0; j < i; j++) |
1664 |
|
{ |
1665 |
|
if (!strcmp(_dyld_get_image_name(j),modname)) |
1666 |
|
{ |
1667 |
|
mh=_dyld_get_image_header(j); |
1668 |
|
break; |
1669 |
|
} |
1670 |
|
} |
1671 |
|
return mh; |
1672 |
|
} |
1673 |
|
|
1674 |
|
static const char* lt_int_dyld_lib_install_name(mh) |
1675 |
|
const struct mach_header *mh; |
1676 |
|
{ |
1677 |
|
/* NSAddImage is also used to get the loaded image, but it only works if the lib |
1678 |
|
is installed, for uninstalled libs we need to check the install_names against |
1679 |
|
each other. Note that this is still broken if DYLD_IMAGE_SUFFIX is set and a |
1680 |
|
different lib was loaded as a result |
1681 |
|
*/ |
1682 |
|
int j; |
1683 |
|
struct load_command *lc; |
1684 |
|
unsigned long offset = sizeof(struct mach_header); |
1685 |
|
const struct mach_header *mh1; |
1686 |
|
const char* retStr=NULL; |
1687 |
|
for (j = 0; j < mh->ncmds; j++) |
1688 |
|
{ |
1689 |
|
lc = (struct load_command*)(((unsigned long)mh) + offset); |
1690 |
|
if (LC_ID_DYLIB == lc->cmd) |
1691 |
|
{ |
1692 |
|
retStr=(char*)(((struct dylib_command*)lc)->dylib.name.offset + |
1693 |
|
(unsigned long)lc); |
1694 |
|
} |
1695 |
|
offset += lc->cmdsize; |
1696 |
|
} |
1697 |
|
return retStr; |
1698 |
|
} |
1699 |
|
|
1700 |
|
static const struct mach_header * |
1701 |
|
lt_int_dyld_match_loaded_lib_by_install_name(const char *name) |
1702 |
|
{ |
1703 |
|
int i=_dyld_image_count(); |
1704 |
|
int j; |
1705 |
|
const struct mach_header *mh=NULL; |
1706 |
|
const char *id=NULL; |
1707 |
|
for (j = 0; j < i; j++) |
1708 |
|
{ |
1709 |
|
id=lt_int_dyld_lib_install_name(_dyld_get_image_header(j)); |
1710 |
|
if ((id) && (!strcmp(id,name))) |
1711 |
|
{ |
1712 |
|
mh=_dyld_get_image_header(j); |
1713 |
|
break; |
1714 |
|
} |
1715 |
|
} |
1716 |
|
return mh; |
1717 |
|
} |
1718 |
|
|
1719 |
|
static NSSymbol |
1720 |
|
lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh) |
1721 |
|
const char *symbol; |
1722 |
|
const struct mach_header *mh; |
1723 |
|
{ |
1724 |
|
/* Safe to assume our mh is good */ |
1725 |
|
int j; |
1726 |
|
struct load_command *lc; |
1727 |
|
unsigned long offset = sizeof(struct mach_header); |
1728 |
|
NSSymbol retSym = 0; |
1729 |
|
const struct mach_header *mh1; |
1730 |
|
if ((ltdl_NSLookupSymbolInImage) && NSIsSymbolNameDefined(symbol) ) |
1731 |
|
{ |
1732 |
|
for (j = 0; j < mh->ncmds; j++) |
1733 |
|
{ |
1734 |
|
lc = (struct load_command*)(((unsigned long)mh) + offset); |
1735 |
|
if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) |
1736 |
|
{ |
1737 |
|
mh1=lt_int_dyld_match_loaded_lib_by_install_name((char*)(((struct dylib_command*)lc)->dylib.name.offset + |
1738 |
|
(unsigned long)lc)); |
1739 |
|
if (!mh1) |
1740 |
|
{ |
1741 |
|
/* Maybe NSAddImage can find it */ |
1742 |
|
mh1=ltdl_NSAddImage((char*)(((struct dylib_command*)lc)->dylib.name.offset + |
1743 |
|
(unsigned long)lc), |
1744 |
|
NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED + |
1745 |
|
NSADDIMAGE_OPTION_WITH_SEARCHING + |
1746 |
|
NSADDIMAGE_OPTION_RETURN_ON_ERROR ); |
1747 |
|
} |
1748 |
|
if (mh1) |
1749 |
|
{ |
1750 |
|
retSym = ltdl_NSLookupSymbolInImage(mh1, |
1751 |
|
symbol, |
1752 |
|
NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
1753 |
|
| NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR |
1754 |
|
); |
1755 |
|
if (retSym) break; |
1756 |
|
} |
1757 |
|
} |
1758 |
|
offset += lc->cmdsize; |
1759 |
|
} |
1760 |
|
} |
1761 |
|
return retSym; |
1762 |
|
} |
1763 |
|
|
1764 |
|
static int |
1765 |
|
sys_dyld_init() |
1766 |
|
{ |
1767 |
|
int retCode = 0; |
1768 |
|
int err = 0; |
1769 |
|
if (!_dyld_present()) { |
1770 |
|
retCode=1; |
1771 |
|
} |
1772 |
|
else { |
1773 |
|
err = _dyld_func_lookup("__dyld_NSAddImage",(unsigned long*)<dl_NSAddImage); |
1774 |
|
err = _dyld_func_lookup("__dyld_NSLookupSymbolInImage",(unsigned long*)<dl_NSLookupSymbolInImage); |
1775 |
|
err = _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",(unsigned long*)<dl_NSIsSymbolNameDefinedInImage); |
1776 |
|
err = _dyld_func_lookup("__dyld_NSMakePrivateModulePublic",(unsigned long*)<dl_NSMakePrivateModulePublic); |
1777 |
|
} |
1778 |
|
return retCode; |
1779 |
|
} |
1780 |
|
|
1781 |
|
static lt_module |
1782 |
|
sys_dyld_open (loader_data, filename) |
1783 |
|
lt_user_data loader_data; |
1784 |
|
const char *filename; |
1785 |
|
{ |
1786 |
|
lt_module module = 0; |
1787 |
|
NSObjectFileImage ofi = 0; |
1788 |
|
NSObjectFileImageReturnCode ofirc; |
1789 |
|
|
1790 |
|
if (!filename) |
1791 |
|
return (lt_module)-1; |
1792 |
|
ofirc = NSCreateObjectFileImageFromFile(filename, &ofi); |
1793 |
|
switch (ofirc) |
1794 |
|
{ |
1795 |
|
case NSObjectFileImageSuccess: |
1796 |
|
module = NSLinkModule(ofi, filename, |
1797 |
|
NSLINKMODULE_OPTION_RETURN_ON_ERROR |
1798 |
|
| NSLINKMODULE_OPTION_PRIVATE |
1799 |
|
| NSLINKMODULE_OPTION_BINDNOW); |
1800 |
|
NSDestroyObjectFileImage(ofi); |
1801 |
|
if (module) |
1802 |
|
ltdl_NSMakePrivateModulePublic(module); |
1803 |
|
break; |
1804 |
|
case NSObjectFileImageInappropriateFile: |
1805 |
|
if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) |
1806 |
|
{ |
1807 |
|
module = (lt_module)ltdl_NSAddImage(filename, NSADDIMAGE_OPTION_RETURN_ON_ERROR); |
1808 |
|
break; |
1809 |
|
} |
1810 |
|
default: |
1811 |
|
LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); |
1812 |
|
return 0; |
1813 |
|
} |
1814 |
|
if (!module) LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); |
1815 |
|
return module; |
1816 |
|
} |
1817 |
|
|
1818 |
|
static int |
1819 |
|
sys_dyld_close (loader_data, module) |
1820 |
|
lt_user_data loader_data; |
1821 |
|
lt_module module; |
1822 |
|
{ |
1823 |
|
int retCode = 0; |
1824 |
|
int flags = 0; |
1825 |
|
unsigned long size=0; |
1826 |
|
if (module == (lt_module)-1) return 0; |
1827 |
|
#ifdef __BIG_ENDIAN__ |
1828 |
|
if (((struct mach_header *)module)->magic == MH_MAGIC) |
1829 |
|
#else |
1830 |
|
if (((struct mach_header *)module)->magic == MH_CIGAM) |
1831 |
|
#endif |
1832 |
|
{ |
1833 |
|
LT_DLMUTEX_SETERROR("Can not close a dylib"); |
1834 |
|
retCode = 1; |
1835 |
|
} |
1836 |
|
else |
1837 |
|
{ |
1838 |
|
#if 1 |
1839 |
|
/* Currently, if a module contains c++ static destructors and it is unloaded, we |
1840 |
|
get a segfault in atexit(), due to compiler and dynamic loader differences of |
1841 |
|
opinion, this works around that. |
1842 |
|
*/ |
1843 |
|
if ((const struct section *)NULL != |
1844 |
|
getsectbynamefromheader(lt_int_dyld_get_mach_header_from_nsmodule(module), |
1845 |
|
"__DATA","__mod_term_func")) |
1846 |
|
{ |
1847 |
|
flags += NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; |
1848 |
|
} |
1849 |
|
#endif |
1850 |
|
#ifdef __ppc__ |
1851 |
|
flags += NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; |
1852 |
|
#endif |
1853 |
|
if (!NSUnLinkModule(module,flags)) |
1854 |
|
{ |
1855 |
|
retCode=1; |
1856 |
|
LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_CLOSE))); |
1857 |
|
} |
1858 |
|
} |
1859 |
|
|
1860 |
|
return retCode; |
1861 |
|
} |
1862 |
|
|
1863 |
|
static lt_ptr |
1864 |
|
sys_dyld_sym (loader_data, module, symbol) |
1865 |
|
lt_user_data loader_data; |
1866 |
|
lt_module module; |
1867 |
|
const char *symbol; |
1868 |
|
{ |
1869 |
|
lt_ptr address = 0; |
1870 |
|
NSSymbol *nssym = 0; |
1871 |
|
void *unused; |
1872 |
|
const struct mach_header *mh=NULL; |
1873 |
|
if (module == (lt_module)-1) |
1874 |
|
{ |
1875 |
|
_dyld_lookup_and_bind(symbol,(unsigned long*)&address,&unused); |
1876 |
|
return address; |
1877 |
|
} |
1878 |
|
#ifdef __BIG_ENDIAN__ |
1879 |
|
if (((struct mach_header *)module)->magic == MH_MAGIC) |
1880 |
|
#else |
1881 |
|
if (((struct mach_header *)module)->magic == MH_CIGAM) |
1882 |
|
#endif |
1883 |
|
{ |
1884 |
|
if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) |
1885 |
|
{ |
1886 |
|
mh=module; |
1887 |
|
if (ltdl_NSIsSymbolNameDefinedInImage((struct mach_header*)module,symbol)) |
1888 |
|
{ |
1889 |
|
nssym = ltdl_NSLookupSymbolInImage((struct mach_header*)module, |
1890 |
|
symbol, |
1891 |
|
NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
1892 |
|
| NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR |
1893 |
|
); |
1894 |
|
} |
1895 |
|
} |
1896 |
|
|
1897 |
|
} |
1898 |
|
else { |
1899 |
|
nssym = NSLookupSymbolInModule(module, symbol); |
1900 |
|
} |
1901 |
|
if (!nssym) |
1902 |
|
{ |
1903 |
|
if (!mh) mh=lt_int_dyld_get_mach_header_from_nsmodule(module); |
1904 |
|
nssym = lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh); |
1905 |
|
} |
1906 |
|
if (!nssym) |
1907 |
|
{ |
1908 |
|
LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(SYMBOL_NOT_FOUND))); |
1909 |
|
return NULL; |
1910 |
|
} |
1911 |
|
return NSAddressOfSymbol(nssym); |
1912 |
|
} |
1913 |
|
|
1914 |
|
static struct lt_user_dlloader sys_dyld = |
1915 |
|
{ "_", sys_dyld_open, sys_dyld_close, sys_dyld_sym, 0, 0 }; |
1916 |
|
|
1917 |
|
|
1918 |
|
#endif /* HAVE_DYLD */ |
1919 |
|
|
1920 |
|
|
1921 |
/* --- DLPREOPEN() INTERFACE LOADER --- */ |
/* --- DLPREOPEN() INTERFACE LOADER --- */ |
1929 |
const lt_dlsymlist *syms; |
const lt_dlsymlist *syms; |
1930 |
} lt_dlsymlists_t; |
} lt_dlsymlists_t; |
1931 |
|
|
1932 |
static const lt_dlsymlist *default_preloaded_symbols = NULL; |
static const lt_dlsymlist *default_preloaded_symbols = 0; |
1933 |
static lt_dlsymlists_t *preloaded_symbols = NULL; |
static lt_dlsymlists_t *preloaded_symbols = 0; |
1934 |
|
|
1935 |
static int |
static int |
1936 |
presym_init (loader_data) |
presym_init (loader_data) |
1940 |
|
|
1941 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
1942 |
|
|
1943 |
preloaded_symbols = NULL; |
preloaded_symbols = 0; |
1944 |
if (default_preloaded_symbols) |
if (default_preloaded_symbols) |
1945 |
{ |
{ |
1946 |
errors = lt_dlpreload (default_preloaded_symbols); |
errors = lt_dlpreload (default_preloaded_symbols); |
1966 |
lists = lists->next; |
lists = lists->next; |
1967 |
LT_DLFREE (tmp); |
LT_DLFREE (tmp); |
1968 |
} |
} |
1969 |
preloaded_symbols = NULL; |
preloaded_symbols = 0; |
1970 |
|
|
1971 |
LT_DLMUTEX_UNLOCK (); |
LT_DLMUTEX_UNLOCK (); |
1972 |
|
|
2075 |
lt_module module; |
lt_module module; |
2076 |
{ |
{ |
2077 |
/* Just to silence gcc -Wall */ |
/* Just to silence gcc -Wall */ |
2078 |
module = NULL; |
module = 0; |
2079 |
return 0; |
return 0; |
2080 |
} |
} |
2081 |
|
|
2178 |
size_t *pargz_len)); |
size_t *pargz_len)); |
2179 |
static int file_not_found LT_PARAMS((void)); |
static int file_not_found LT_PARAMS((void)); |
2180 |
|
|
2181 |
static char *user_search_path= NULL; |
static char *user_search_path= 0; |
2182 |
static lt_dlloader *loaders = NULL; |
static lt_dlloader *loaders = 0; |
2183 |
static lt_dlhandle handles = NULL; |
static lt_dlhandle handles = 0; |
2184 |
static int initialized = 0; |
static int initialized = 0; |
2185 |
|
|
2186 |
/* Initialize libltdl. */ |
/* Initialize libltdl. */ |
2194 |
/* Initialize only at first call. */ |
/* Initialize only at first call. */ |
2195 |
if (++initialized == 1) |
if (++initialized == 1) |
2196 |
{ |
{ |
2197 |
handles = NULL; |
handles = 0; |
2198 |
user_search_path = NULL; /* empty search path */ |
user_search_path = 0; /* empty search path */ |
2199 |
|
|
2200 |
#if HAVE_LIBDL && !defined(__CYGWIN__) |
#if HAVE_LIBDL |
2201 |
errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dl, "dlopen"); |
errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dl, "dlopen"); |
2202 |
#endif |
#endif |
2203 |
#if HAVE_SHL_LOAD |
#if HAVE_SHL_LOAD |
2212 |
#if HAVE_DLD |
#if HAVE_DLD |
2213 |
errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dld, "dld"); |
errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dld, "dld"); |
2214 |
#endif |
#endif |
2215 |
|
#if HAVE_DYLD |
2216 |
|
errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dyld, "dyld"); |
2217 |
|
errors += sys_dyld_init(); |
2218 |
|
#endif |
2219 |
errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload"); |
errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload"); |
2220 |
|
|
2221 |
if (presym_init (presym.dlloader_data)) |
if (presym_init (presym.dlloader_data)) |
2334 |
|
|
2335 |
LT_DLMEM_REASSIGN (loader, next); |
LT_DLMEM_REASSIGN (loader, next); |
2336 |
} |
} |
2337 |
loaders = NULL; |
loaders = 0; |
2338 |
} |
} |
2339 |
|
|
2340 |
done: |
done: |
2386 |
cur = *handle; |
cur = *handle; |
2387 |
if (filename) |
if (filename) |
2388 |
{ |
{ |
2389 |
|
/* Comment out the check of file permissions using access. |
2390 |
|
This call seems to always return -1 with error EACCES. |
2391 |
|
*/ |
2392 |
|
/* We need to catch missing file errors early so that |
2393 |
|
file_not_found() can detect what happened. |
2394 |
|
if (access (filename, R_OK) != 0) |
2395 |
|
{ |
2396 |
|
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); |
2397 |
|
++errors; |
2398 |
|
goto done; |
2399 |
|
} */ |
2400 |
|
|
2401 |
cur->info.filename = lt_estrdup (filename); |
cur->info.filename = lt_estrdup (filename); |
2402 |
if (!cur->info.filename) |
if (!cur->info.filename) |
2403 |
{ |
{ |
2407 |
} |
} |
2408 |
else |
else |
2409 |
{ |
{ |
2410 |
cur->info.filename = NULL; |
cur->info.filename = 0; |
2411 |
} |
} |
2412 |
|
|
2413 |
while (loader) |
while (loader) |
2416 |
|
|
2417 |
cur->module = loader->module_open (data, filename); |
cur->module = loader->module_open (data, filename); |
2418 |
|
|
2419 |
if (cur->module != NULL) |
if (cur->module != 0) |
2420 |
{ |
{ |
2421 |
break; |
break; |
2422 |
} |
} |
2447 |
const char *dlname; |
const char *dlname; |
2448 |
{ |
{ |
2449 |
int error = 0; |
int error = 0; |
2450 |
char *filename = NULL; |
char *filename = 0; |
2451 |
size_t filename_len = 0; |
size_t filename_len = 0; |
2452 |
size_t dirname_len = LT_STRLEN (dirname); |
size_t dirname_len = LT_STRLEN (dirname); |
2453 |
|
|
2457 |
#ifdef LT_DIRSEP_CHAR |
#ifdef LT_DIRSEP_CHAR |
2458 |
/* Only canonicalized names (i.e. with DIRSEP chars already converted) |
/* Only canonicalized names (i.e. with DIRSEP chars already converted) |
2459 |
should make it into this function: */ |
should make it into this function: */ |
2460 |
assert (strchr (dirname, LT_DIRSEP_CHAR) == NULL); |
assert (strchr (dirname, LT_DIRSEP_CHAR) == 0); |
2461 |
#endif |
#endif |
2462 |
|
|
2463 |
if (dirname_len > 0) |
if (dirname_len > 0) |
2542 |
const char *path; |
const char *path; |
2543 |
char **pcanonical; |
char **pcanonical; |
2544 |
{ |
{ |
2545 |
char *canonical = NULL; |
char *canonical = 0; |
2546 |
|
|
2547 |
assert (path && *path); |
assert (path && *path); |
2548 |
assert (pcanonical); |
assert (pcanonical); |
2646 |
int filenamesize = 0; |
int filenamesize = 0; |
2647 |
size_t lenbase = LT_STRLEN (base_name); |
size_t lenbase = LT_STRLEN (base_name); |
2648 |
size_t argz_len = 0; |
size_t argz_len = 0; |
2649 |
char *argz = NULL; |
char *argz = 0; |
2650 |
char *filename = NULL; |
char *filename = 0; |
2651 |
char *canonical = NULL; |
char *canonical = 0; |
2652 |
|
|
2653 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
2654 |
|
|
2665 |
goto cleanup; |
goto cleanup; |
2666 |
|
|
2667 |
{ |
{ |
2668 |
char *dir_name = NULL; |
char *dir_name = 0; |
2669 |
while ((dir_name = argz_next (argz, argz_len, dir_name))) |
while ((dir_name = argz_next (argz, argz_len, dir_name))) |
2670 |
{ |
{ |
2671 |
size_t lendir = LT_STRLEN (dir_name); |
size_t lendir = LT_STRLEN (dir_name); |
2732 |
|
|
2733 |
LT_DLFREE (*pdir); |
LT_DLFREE (*pdir); |
2734 |
*pdir = lt_estrdup (filename); |
*pdir = lt_estrdup (filename); |
2735 |
is_done = (*pdir == NULL) ? -1 : 1; |
is_done = (*pdir == 0) ? -1 : 1; |
2736 |
} |
} |
2737 |
|
|
2738 |
return is_done; |
return is_done; |
2744 |
const char *base_name; |
const char *base_name; |
2745 |
char **pdir; |
char **pdir; |
2746 |
{ |
{ |
2747 |
FILE *file = NULL; |
FILE *file = 0; |
2748 |
|
|
2749 |
foreach_dirinpath (search_path, base_name, find_file_callback, pdir, &file); |
foreach_dirinpath (search_path, base_name, find_file_callback, pdir, &file); |
2750 |
|
|
2767 |
/* Try to dlopen the file, but do not continue searching in any |
/* Try to dlopen the file, but do not continue searching in any |
2768 |
case. */ |
case. */ |
2769 |
if (tryall_dlopen (handle, filename) != 0) |
if (tryall_dlopen (handle, filename) != 0) |
2770 |
*handle = NULL; |
*handle = 0; |
2771 |
|
|
2772 |
return 1; |
return 1; |
2773 |
} |
} |
2796 |
char *deplibs; |
char *deplibs; |
2797 |
{ |
{ |
2798 |
#if LTDL_DLOPEN_DEPLIBS |
#if LTDL_DLOPEN_DEPLIBS |
2799 |
char *p, *save_search_path = NULL; |
char *p, *save_search_path = 0; |
2800 |
int depcount = 0; |
int depcount = 0; |
2801 |
int i; |
int i; |
2802 |
char **names = NULL; |
char **names = 0; |
2803 |
#endif |
#endif |
2804 |
int errors = 0; |
int errors = 0; |
2805 |
|
|
2835 |
if (strncmp(p, "-L", 2) == 0 || strncmp(p, "-R", 2) == 0) |
if (strncmp(p, "-L", 2) == 0 || strncmp(p, "-R", 2) == 0) |
2836 |
{ |
{ |
2837 |
char save = *end; |
char save = *end; |
2838 |
*end = '\0'; /* set a temporary string terminator */ |
*end = 0; /* set a temporary string terminator */ |
2839 |
if (lt_dladdsearchdir(p+2)) |
if (lt_dladdsearchdir(p+2)) |
2840 |
{ |
{ |
2841 |
goto cleanup; |
goto cleanup; |
2892 |
{ |
{ |
2893 |
char *name; |
char *name; |
2894 |
char save = *end; |
char save = *end; |
2895 |
*end = '\0'; /* set a temporary string terminator */ |
*end = 0; /* set a temporary string terminator */ |
2896 |
if (strncmp(p, "-l", 2) == 0) |
if (strncmp(p, "-l", 2) == 0) |
2897 |
{ |
{ |
2898 |
size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2); |
size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2); |
2998 |
} |
} |
2999 |
else |
else |
3000 |
{ |
{ |
3001 |
*dest = NULL; |
*dest = 0; |
3002 |
} |
} |
3003 |
|
|
3004 |
return 0; |
return 0; |
3024 |
lt_dlhandle *phandle; |
lt_dlhandle *phandle; |
3025 |
const char *filename; |
const char *filename; |
3026 |
{ |
{ |
3027 |
const char * ext = NULL; |
const char * ext = 0; |
3028 |
const char * saved_error = NULL; |
const char * saved_error = 0; |
3029 |
char * canonical = NULL; |
char * canonical = 0; |
3030 |
char * base_name = NULL; |
char * base_name = 0; |
3031 |
char * dir = NULL; |
char * dir = 0; |
3032 |
char * name = NULL; |
char * name = 0; |
3033 |
int errors = 0; |
int errors = 0; |
3034 |
lt_dlhandle newhandle; |
lt_dlhandle newhandle; |
3035 |
|
|
3036 |
assert (phandle); |
assert (phandle); |
3037 |
assert (*phandle == NULL); |
assert (*phandle == 0); |
3038 |
|
|
3039 |
LT_DLMUTEX_GETERROR (saved_error); |
LT_DLMUTEX_GETERROR (saved_error); |
3040 |
|
|
3042 |
if (!filename) |
if (!filename) |
3043 |
{ |
{ |
3044 |
*phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
*phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
3045 |
if (*phandle == NULL) |
if (*phandle == 0) |
3046 |
return 1; |
return 1; |
3047 |
|
|
3048 |
memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); |
memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); |
3099 |
if (ext && strcmp (ext, archive_ext) == 0) |
if (ext && strcmp (ext, archive_ext) == 0) |
3100 |
{ |
{ |
3101 |
/* this seems to be a libtool module */ |
/* this seems to be a libtool module */ |
3102 |
FILE * file = NULL; |
FILE * file = 0; |
3103 |
char * dlname = NULL; |
char * dlname = 0; |
3104 |
char * old_name = NULL; |
char * old_name = 0; |
3105 |
char * libdir = NULL; |
char * libdir = 0; |
3106 |
char * deplibs = NULL; |
char * deplibs = 0; |
3107 |
char * line = NULL; |
char * line = 0; |
3108 |
size_t line_len; |
size_t line_len; |
3109 |
|
|
3110 |
/* if we can't find the installed flag, it is probably an |
/* if we can't find the installed flag, it is probably an |
3267 |
errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); |
errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); |
3268 |
if (!errors |
if (!errors |
3269 |
&& dlname |
&& dlname |
3270 |
&& (last_libname = strrchr (dlname, ' ')) != NULL) |
&& (last_libname = strrchr (dlname, ' ')) != 0) |
3271 |
{ |
{ |
3272 |
last_libname = lt_estrdup (last_libname + 1); |
last_libname = lt_estrdup (last_libname + 1); |
3273 |
if (!last_libname) |
if (!last_libname) |
3288 |
|
|
3289 |
/* allocate the handle */ |
/* allocate the handle */ |
3290 |
*phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
*phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
3291 |
if (*phandle == NULL) |
if (*phandle == 0) |
3292 |
++errors; |
++errors; |
3293 |
|
|
3294 |
if (errors) |
if (errors) |
3332 |
{ |
{ |
3333 |
/* not a libtool module */ |
/* not a libtool module */ |
3334 |
*phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
*phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
3335 |
if (*phandle == NULL) |
if (*phandle == 0) |
3336 |
{ |
{ |
3337 |
++errors; |
++errors; |
3338 |
goto cleanup; |
goto cleanup; |
3399 |
lt_dlopen (filename) |
lt_dlopen (filename) |
3400 |
const char *filename; |
const char *filename; |
3401 |
{ |
{ |
3402 |
lt_dlhandle handle = NULL; |
lt_dlhandle handle = 0; |
3403 |
|
|
3404 |
/* Just incase we missed a code path in try_dlopen() that reports |
/* Just incase we missed a code path in try_dlopen() that reports |
3405 |
an error, but forgets to reset handle... */ |
an error, but forgets to reset handle... */ |
3414 |
static int |
static int |
3415 |
file_not_found () |
file_not_found () |
3416 |
{ |
{ |
3417 |
const char *error = NULL; |
const char *error = 0; |
3418 |
|
|
3419 |
LT_DLMUTEX_GETERROR (error); |
LT_DLMUTEX_GETERROR (error); |
3420 |
if (error == LT_DLSTRERROR (FILE_NOT_FOUND)) |
if (error == LT_DLSTRERROR (FILE_NOT_FOUND)) |
3431 |
lt_dlopenext (filename) |
lt_dlopenext (filename) |
3432 |
const char *filename; |
const char *filename; |
3433 |
{ |
{ |
3434 |
lt_dlhandle handle = NULL; |
lt_dlhandle handle = 0; |
3435 |
char * tmp = NULL; |
char * tmp = 0; |
3436 |
char * ext = NULL; |
char * ext = 0; |
3437 |
size_t len; |
size_t len; |
3438 |
int errors = 0; |
int errors = 0; |
3439 |
|
|
3546 |
size_t *pargz_len; |
size_t *pargz_len; |
3547 |
const char *entry; |
const char *entry; |
3548 |
{ |
{ |
3549 |
char *before = NULL; |
char *before = 0; |
3550 |
|
|
3551 |
assert (pargz); |
assert (pargz); |
3552 |
assert (pargz_len); |
assert (pargz_len); |
3571 |
const char *dirnam; |
const char *dirnam; |
3572 |
struct dirent *dp; |
struct dirent *dp; |
3573 |
{ |
{ |
3574 |
char *buf = NULL; |
char *buf = 0; |
3575 |
size_t buf_len = 0; |
size_t buf_len = 0; |
3576 |
char *end = NULL; |
char *end = 0; |
3577 |
size_t end_offset = 0; |
size_t end_offset = 0; |
3578 |
size_t dir_len = 0; |
size_t dir_len = 0; |
3579 |
int errors = 0; |
int errors = 0; |
3636 |
char **pargz; |
char **pargz; |
3637 |
size_t *pargz_len; |
size_t *pargz_len; |
3638 |
{ |
{ |
3639 |
DIR *dirp = NULL; |
DIR *dirp = 0; |
3640 |
int errors = 0; |
int errors = 0; |
3641 |
|
|
3642 |
assert (dirnam && *dirnam); |
assert (dirnam && *dirnam); |
3647 |
dirp = opendir (dirnam); |
dirp = opendir (dirnam); |
3648 |
if (dirp) |
if (dirp) |
3649 |
{ |
{ |
3650 |
struct dirent *dp = NULL; |
struct dirent *dp = 0; |
3651 |
|
|
3652 |
while ((dp = readdir (dirp))) |
while ((dp = readdir (dirp))) |
3653 |
if (dp->d_name[0] != '.') |
if (dp->d_name[0] != '.') |
3678 |
= (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1; |
= (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1; |
3679 |
|
|
3680 |
int is_done = 0; |
int is_done = 0; |
3681 |
char *argz = NULL; |
char *argz = 0; |
3682 |
size_t argz_len = 0; |
size_t argz_len = 0; |
3683 |
|
|
3684 |
if (list_files_by_dir (dirname, &argz, &argz_len) != 0) |
if (list_files_by_dir (dirname, &argz, &argz_len) != 0) |
3687 |
goto cleanup; |
goto cleanup; |
3688 |
|
|
3689 |
{ |
{ |
3690 |
char *filename = NULL; |
char *filename = 0; |
3691 |
while ((filename = argz_next (argz, argz_len, filename))) |
while ((filename = argz_next (argz, argz_len, filename))) |
3692 |
if ((is_done = (*func) (filename, data2))) |
if ((is_done = (*func) (filename, data2))) |
3693 |
break; |
break; |
3931 |
const char *dir; |
const char *dir; |
3932 |
{ |
{ |
3933 |
int errors = 0; |
int errors = 0; |
3934 |
char *canonical = NULL; |
char *canonical = 0; |
3935 |
char *argz = NULL; |
char *argz = 0; |
3936 |
size_t argz_len = 0; |
size_t argz_len = 0; |
3937 |
|
|
3938 |
assert (ppath); |
assert (ppath); |
3947 |
assert (canonical && *canonical); |
assert (canonical && *canonical); |
3948 |
|
|
3949 |
/* If *PPATH is empty, set it to DIR. */ |
/* If *PPATH is empty, set it to DIR. */ |
3950 |
if (*ppath == NULL) |
if (*ppath == 0) |
3951 |
{ |
{ |
3952 |
assert (!before); /* BEFORE cannot be set without PPATH. */ |
assert (!before); /* BEFORE cannot be set without PPATH. */ |
3953 |
assert (dir); /* Without DIR, don't call this function! */ |
assert (dir); /* Without DIR, don't call this function! */ |
3954 |
|
|
3955 |
*ppath = lt_estrdup (dir); |
*ppath = lt_estrdup (dir); |
3956 |
if (*ppath == NULL) |
if (*ppath == 0) |
3957 |
++errors; |
++errors; |
3958 |
|
|
3959 |
return errors; |
return errors; |
4187 |
lt_ptr data; |
lt_ptr data; |
4188 |
{ |
{ |
4189 |
int n_elements = 0; |
int n_elements = 0; |
4190 |
lt_ptr stale = NULL; |
lt_ptr stale = (lt_ptr) 0; |
4191 |
int i; |
int i; |
4192 |
|
|
4193 |
/* This needs to be locked so that the caller data can be updated |
/* This needs to be locked so that the caller data can be updated |
4216 |
|
|
4217 |
if (!temp) |
if (!temp) |
4218 |
{ |
{ |
4219 |
stale = NULL; |
stale = 0; |
4220 |
goto done; |
goto done; |
4221 |
} |
} |
4222 |
|
|
4276 |
const char *loader_name; |
const char *loader_name; |
4277 |
{ |
{ |
4278 |
int errors = 0; |
int errors = 0; |
4279 |
lt_dlloader *node = NULL, *ptr = NULL; |
lt_dlloader *node = 0, *ptr = 0; |
4280 |
|
|
4281 |
if ((dlloader == NULL) /* diagnose null parameters */ |
if ((dlloader == 0) /* diagnose null parameters */ |
4282 |
|| (dlloader->module_open == NULL) |
|| (dlloader->module_open == 0) |
4283 |
|| (dlloader->module_close == NULL) |
|| (dlloader->module_close == 0) |
4284 |
|| (dlloader->find_sym == NULL)) |
|| (dlloader->find_sym == 0)) |
4285 |
{ |
{ |
4286 |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); |
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); |
4287 |
return 1; |
return 1; |
4292 |
if (!node) |
if (!node) |
4293 |
return 1; |
return 1; |
4294 |
|
|
4295 |
node->next = NULL; |
node->next = 0; |
4296 |
node->loader_name = loader_name; |
node->loader_name = loader_name; |
4297 |
node->sym_prefix = dlloader->sym_prefix; |
node->sym_prefix = dlloader->sym_prefix; |
4298 |
node->dlloader_exit = dlloader->dlloader_exit; |
node->dlloader_exit = dlloader->dlloader_exit; |
4428 |
lt_dlloader_name (place) |
lt_dlloader_name (place) |
4429 |
lt_dlloader *place; |
lt_dlloader *place; |
4430 |
{ |
{ |
4431 |
const char *name = NULL; |
const char *name = 0; |
4432 |
|
|
4433 |
if (place) |
if (place) |
4434 |
{ |
{ |
4448 |
lt_dlloader_data (place) |
lt_dlloader_data (place) |
4449 |
lt_dlloader *place; |
lt_dlloader *place; |
4450 |
{ |
{ |
4451 |
lt_user_data *data = NULL; |
lt_user_data *data = 0; |
4452 |
|
|
4453 |
if (place) |
if (place) |
4454 |
{ |
{ |
4468 |
lt_dlloader_find (loader_name) |
lt_dlloader_find (loader_name) |
4469 |
const char *loader_name; |
const char *loader_name; |
4470 |
{ |
{ |
4471 |
lt_dlloader *place = NULL; |
lt_dlloader *place = 0; |
4472 |
|
|
4473 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
4474 |
for (place = loaders; place; place = place->next) |
for (place = loaders; place; place = place->next) |