aboutsummaryrefslogtreecommitdiff
path: root/libltdl/ltdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'libltdl/ltdl.c')
-rw-r--r--libltdl/ltdl.c2464
1 files changed, 1253 insertions, 1211 deletions
diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c
index 60feb043..8ad947dc 100644
--- a/libltdl/ltdl.c
+++ b/libltdl/ltdl.c
@@ -131,10 +131,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
131#if WITH_DMALLOC 131#if WITH_DMALLOC
132# include <dmalloc.h> 132# include <dmalloc.h>
133#endif 133#endif
134
134 135
135 136
136 137
137
138/* --- WINDOWS SUPPORT --- */ 138/* --- WINDOWS SUPPORT --- */
139 139
140 140
@@ -162,7 +162,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
162struct dirent 162struct dirent
163{ 163{
164 char d_name[2048]; 164 char d_name[2048];
165 int d_namlen; 165 int d_namlen;
166}; 166};
167 167
168typedef struct _DIR 168typedef struct _DIR
@@ -174,8 +174,8 @@ typedef struct _DIR
174} DIR; 174} DIR;
175 175
176#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ 176#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */
177
178 177
178
179/* --- MANIFEST CONSTANTS --- */ 179/* --- MANIFEST CONSTANTS --- */
180 180
181 181
@@ -199,30 +199,32 @@ typedef struct _DIR
199/* This accounts for the _LTX_ separator */ 199/* This accounts for the _LTX_ separator */
200#undef LT_SYMBOL_OVERHEAD 200#undef LT_SYMBOL_OVERHEAD
201#define LT_SYMBOL_OVERHEAD 5 201#define LT_SYMBOL_OVERHEAD 5
202
202 203
203 204
204 205
205
206/* --- MEMORY HANDLING --- */ 206/* --- MEMORY HANDLING --- */
207 207
208 208
209/* These are the functions used internally. In addition to making 209/* These are the functions used internally. In addition to making
210 use of the associated function pointers above, they also perform 210 use of the associated function pointers above, they also perform
211 error handling. */ 211 error handling. */
212static char *lt_estrdup LT_PARAMS((const char *str)); 212static char *lt_estrdup LT_PARAMS ((const char *str));
213static lt_ptr lt_emalloc LT_PARAMS((size_t size)); 213static lt_ptr lt_emalloc LT_PARAMS ((size_t size));
214static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size)); 214static lt_ptr lt_erealloc LT_PARAMS ((lt_ptr addr, size_t size));
215 215
216/* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */ 216/* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */
217#define rpl_realloc realloc 217#define rpl_realloc realloc
218 218
219/* These are the pointers that can be changed by the caller: */ 219/* These are the pointers that can be changed by the caller: */
220LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)) 220LT_GLOBAL_DATA
221 = (lt_ptr (*) LT_PARAMS((size_t))) malloc; 221lt_ptr (*lt_dlmalloc)
222LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)) 222LT_PARAMS ((size_t size)) = (lt_ptr (*)LT_PARAMS ((size_t))) malloc;
223 = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) rpl_realloc; 223 LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc)
224LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) 224 LT_PARAMS ((lt_ptr ptr, size_t size)) =
225 = (void (*) LT_PARAMS((lt_ptr))) free; 225 (lt_ptr (*)LT_PARAMS ((lt_ptr, size_t))) rpl_realloc;
226 LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS ((lt_ptr ptr)) =
227 (void (*)LT_PARAMS ((lt_ptr))) free;
226 228
227/* The following macros reduce the amount of typing needed to cast 229/* The following macros reduce the amount of typing needed to cast
228 assigned memory. */ 230 assigned memory. */
@@ -251,29 +253,28 @@ LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr))
251#define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \ 253#define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \
252 if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \ 254 if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \
253 } LT_STMT_END 255 } LT_STMT_END
254
255 256
257
256/* --- REPLACEMENT FUNCTIONS --- */ 258/* --- REPLACEMENT FUNCTIONS --- */
257 259
258 260
259#undef strdup 261#undef strdup
260#define strdup rpl_strdup 262#define strdup rpl_strdup
261 263
262static char *strdup LT_PARAMS((const char *str)); 264 static char *strdup LT_PARAMS ((const char *str));
263 265
264static char * 266 static char *strdup (str)
265strdup(str)
266 const char *str; 267 const char *str;
267{ 268{
268 char *tmp = 0; 269 char *tmp = 0;
269 270
270 if (str) 271 if (str)
271 { 272 {
272 tmp = LT_DLMALLOC (char, 1+ strlen (str)); 273 tmp = LT_DLMALLOC (char, 1 + strlen (str));
273 if (tmp) 274 if (tmp)
274 { 275 {
275 strcpy(tmp, str); 276 strcpy (tmp, str);
276 } 277 }
277 } 278 }
278 279
279 return tmp; 280 return tmp;
@@ -285,7 +286,7 @@ strdup(str)
285#undef strcmp 286#undef strcmp
286#define strcmp rpl_strcmp 287#define strcmp rpl_strcmp
287 288
288static int strcmp LT_PARAMS((const char *str1, const char *str2)); 289static int strcmp LT_PARAMS ((const char *str1, const char *str2));
289 290
290static int 291static int
291strcmp (str1, str2) 292strcmp (str1, str2)
@@ -299,13 +300,13 @@ strcmp (str1, str2)
299 if (str2 == 0) 300 if (str2 == 0)
300 return 1; 301 return 1;
301 302
302 for (;*str1 && *str2; ++str1, ++str2) 303 for (; *str1 && *str2; ++str1, ++str2)
303 { 304 {
304 if (*str1 != *str2) 305 if (*str1 != *str2)
305 break; 306 break;
306 } 307 }
307 308
308 return (int)(*str1 - *str2); 309 return (int) (*str1 - *str2);
309} 310}
310#endif 311#endif
311 312
@@ -317,19 +318,19 @@ strcmp (str1, str2)
317# else 318# else
318# define strchr rpl_strchr 319# define strchr rpl_strchr
319 320
320static const char *strchr LT_PARAMS((const char *str, int ch)); 321static const char *strchr LT_PARAMS ((const char *str, int ch));
321 322
322static const char* 323static const char *
323strchr(str, ch) 324strchr (str, ch)
324 const char *str; 325 const char *str;
325 int ch; 326 int ch;
326{ 327{
327 const char *p; 328 const char *p;
328 329
329 for (p = str; *p != (char)ch && *p != LT_EOS_CHAR; ++p) 330 for (p = str; *p != (char) ch && *p != LT_EOS_CHAR; ++p)
330 /*NOWORK*/; 331 /*NOWORK*/;
331 332
332 return (*p == (char)ch) ? p : 0; 333 return (*p == (char) ch) ? p : 0;
333} 334}
334 335
335# endif 336# endif
@@ -343,10 +344,10 @@ strchr(str, ch)
343# else 344# else
344# define strrchr rpl_strrchr 345# define strrchr rpl_strrchr
345 346
346static const char *strrchr LT_PARAMS((const char *str, int ch)); 347static const char *strrchr LT_PARAMS ((const char *str, int ch));
347 348
348static const char* 349static const char *
349strrchr(str, ch) 350strrchr (str, ch)
350 const char *str; 351 const char *str;
351 int ch; 352 int ch;
352{ 353{
@@ -355,9 +356,9 @@ strrchr(str, ch)
355 for (p = str; *p != LT_EOS_CHAR; ++p) 356 for (p = str; *p != LT_EOS_CHAR; ++p)
356 { 357 {
357 if (*p == (char) ch) 358 if (*p == (char) ch)
358 { 359 {
359 q = p; 360 q = p;
360 } 361 }
361 } 362 }
362 363
363 return q; 364 return q;
@@ -377,7 +378,7 @@ strrchr(str, ch)
377# else 378# else
378# define memcpy rpl_memcpy 379# define memcpy rpl_memcpy
379 380
380static lt_ptr memcpy LT_PARAMS((lt_ptr dest, const lt_ptr src, size_t size)); 381static lt_ptr memcpy LT_PARAMS ((lt_ptr dest, const lt_ptr src, size_t size));
381 382
382static lt_ptr 383static lt_ptr
383memcpy (dest, src, size) 384memcpy (dest, src, size)
@@ -396,12 +397,13 @@ memcpy (dest, src, size)
396} 397}
397 398
398# endif /* !HAVE_BCOPY */ 399# endif /* !HAVE_BCOPY */
399#endif /* !HAVE_MEMCPY */ 400#endif /* !HAVE_MEMCPY */
400 401
401#if ! HAVE_MEMMOVE 402#if ! HAVE_MEMMOVE
402# define memmove rpl_memmove 403# define memmove rpl_memmove
403 404
404static lt_ptr memmove LT_PARAMS((lt_ptr dest, const lt_ptr src, size_t size)); 405static lt_ptr memmove
406LT_PARAMS ((lt_ptr dest, const lt_ptr src, size_t size));
405 407
406static lt_ptr 408static lt_ptr
407memmove (dest, src, size) 409memmove (dest, src, size)
@@ -414,12 +416,12 @@ memmove (dest, src, size)
414 if (dest < src) 416 if (dest < src)
415 for (i = 0; i < size; ++i) 417 for (i = 0; i < size; ++i)
416 { 418 {
417 dest[i] = src[i]; 419 dest[i] = src[i];
418 } 420 }
419 else if (dest > src) 421 else if (dest > src)
420 for (i = size -1; i >= 0; --i) 422 for (i = size - 1; i >= 0; --i)
421 { 423 {
422 dest[i] = src[i]; 424 dest[i] = src[i];
423 } 425 }
424 426
425 return dest; 427 return dest;
@@ -429,71 +431,73 @@ memmove (dest, src, size)
429 431
430#ifdef LT_USE_WINDOWS_DIRENT_EMULATION 432#ifdef LT_USE_WINDOWS_DIRENT_EMULATION
431 433
432static void closedir LT_PARAMS((DIR *entry)); 434static void closedir LT_PARAMS ((DIR * entry));
433 435
434static void 436static void
435closedir(entry) 437closedir (entry)
436 DIR *entry; 438 DIR *entry;
437{ 439{
438 assert(entry != (DIR *) NULL); 440 assert (entry != (DIR *) NULL);
439 FindClose(entry->hSearch); 441 FindClose (entry->hSearch);
440 lt_dlfree((lt_ptr)entry); 442 lt_dlfree ((lt_ptr) entry);
441} 443}
442 444
443 445
444static DIR * opendir LT_PARAMS((const char *path)); 446static DIR *opendir LT_PARAMS ((const char *path));
445 447
446static DIR* 448static DIR *
447opendir (path) 449opendir (path)
448 const char *path; 450 const char *path;
449{ 451{
450 char file_specification[LT_FILENAME_MAX]; 452 char file_specification[LT_FILENAME_MAX];
451 DIR *entry; 453 DIR *entry;
452 454
453 assert(path != (char *) NULL); 455 assert (path != (char *) NULL);
454 (void) strncpy(file_specification,path,LT_FILENAME_MAX-1); 456 (void) strncpy (file_specification, path, LT_FILENAME_MAX - 1);
455 (void) strcat(file_specification,"\\"); 457 (void) strcat (file_specification, "\\");
456 entry = LT_DLMALLOC (DIR,sizeof(DIR)); 458 entry = LT_DLMALLOC (DIR, sizeof (DIR));
457 if (entry != (DIR *) 0) 459 if (entry != (DIR *) 0)
458 { 460 {
459 entry->firsttime = TRUE; 461 entry->firsttime = TRUE;
460 entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); 462 entry->hSearch =
463 FindFirstFile (file_specification, &entry->Win32FindData);
461 } 464 }
462 if (entry->hSearch == INVALID_HANDLE_VALUE) 465 if (entry->hSearch == INVALID_HANDLE_VALUE)
463 { 466 {
464 (void) strcat(file_specification,"\\*.*"); 467 (void) strcat (file_specification, "\\*.*");
465 entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); 468 entry->hSearch =
469 FindFirstFile (file_specification, &entry->Win32FindData);
466 if (entry->hSearch == INVALID_HANDLE_VALUE) 470 if (entry->hSearch == INVALID_HANDLE_VALUE)
467 { 471 {
468 LT_DLFREE (entry); 472 LT_DLFREE (entry);
469 return (DIR *) 0; 473 return (DIR *) 0;
470 } 474 }
471 } 475 }
472 return(entry); 476 return (entry);
473} 477}
474 478
475 479
476static struct dirent *readdir LT_PARAMS((DIR *entry)); 480static struct dirent *readdir LT_PARAMS ((DIR * entry));
477 481
478static struct dirent *readdir(entry) 482static struct dirent *
479 DIR *entry; 483readdir (entry)
484 DIR *entry;
480{ 485{
481 int 486 int status;
482 status;
483 487
484 if (entry == (DIR *) 0) 488 if (entry == (DIR *) 0)
485 return((struct dirent *) 0); 489 return ((struct dirent *) 0);
486 if (!entry->firsttime) 490 if (!entry->firsttime)
487 { 491 {
488 status = FindNextFile(entry->hSearch,&entry->Win32FindData); 492 status = FindNextFile (entry->hSearch, &entry->Win32FindData);
489 if (status == 0) 493 if (status == 0)
490 return((struct dirent *) 0); 494 return ((struct dirent *) 0);
491 } 495 }
492 entry->firsttime = FALSE; 496 entry->firsttime = FALSE;
493 (void) strncpy(entry->file_info.d_name,entry->Win32FindData.cFileName, 497 (void) strncpy (entry->file_info.d_name, entry->Win32FindData.cFileName,
494 LT_FILENAME_MAX-1); 498 LT_FILENAME_MAX - 1);
495 entry->file_info.d_namlen = strlen(entry->file_info.d_name); 499 entry->file_info.d_namlen = strlen (entry->file_info.d_name);
496 return(&entry->file_info); 500 return (&entry->file_info);
497} 501}
498 502
499#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ 503#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */
@@ -524,9 +528,9 @@ realloc (ptr, size)
524 { 528 {
525 /* For zero or less bytes, free the original memory */ 529 /* For zero or less bytes, free the original memory */
526 if (ptr != 0) 530 if (ptr != 0)
527 { 531 {
528 lt_dlfree (ptr); 532 lt_dlfree (ptr);
529 } 533 }
530 534
531 return (lt_ptr) 0; 535 return (lt_ptr) 0;
532 } 536 }
@@ -541,13 +545,13 @@ realloc (ptr, size)
541 lt_ptr mem = lt_dlmalloc (size); 545 lt_ptr mem = lt_dlmalloc (size);
542 546
543 if (mem) 547 if (mem)
544 { 548 {
545 memcpy (mem, ptr, size); 549 memcpy (mem, ptr, size);
546 lt_dlfree (ptr); 550 lt_dlfree (ptr);
547 } 551 }
548 552
549 /* Note that the contents of PTR are not damaged if there is 553 /* Note that the contents of PTR are not damaged if there is
550 insufficient memory to realloc. */ 554 insufficient memory to realloc. */
551 return mem; 555 return mem;
552 } 556 }
553} 557}
@@ -557,8 +561,8 @@ realloc (ptr, size)
557#if ! HAVE_ARGZ_APPEND 561#if ! HAVE_ARGZ_APPEND
558# define argz_append rpl_argz_append 562# define argz_append rpl_argz_append
559 563
560static error_t argz_append LT_PARAMS((char **pargz, size_t *pargz_len, 564static error_t argz_append LT_PARAMS ((char **pargz, size_t * pargz_len,
561 const char *buf, size_t buf_len)); 565 const char *buf, size_t buf_len));
562 566
563static error_t 567static error_t
564argz_append (pargz, pargz_len, buf, buf_len) 568argz_append (pargz, pargz_len, buf, buf_len)
@@ -568,7 +572,7 @@ argz_append (pargz, pargz_len, buf, buf_len)
568 size_t buf_len; 572 size_t buf_len;
569{ 573{
570 size_t argz_len; 574 size_t argz_len;
571 char *argz; 575 char *argz;
572 576
573 assert (pargz); 577 assert (pargz);
574 assert (pargz_len); 578 assert (pargz_len);
@@ -599,8 +603,8 @@ argz_append (pargz, pargz_len, buf, buf_len)
599#if ! HAVE_ARGZ_CREATE_SEP 603#if ! HAVE_ARGZ_CREATE_SEP
600# define argz_create_sep rpl_argz_create_sep 604# define argz_create_sep rpl_argz_create_sep
601 605
602static error_t argz_create_sep LT_PARAMS((const char *str, int delim, 606static error_t argz_create_sep LT_PARAMS ((const char *str, int delim,
603 char **pargz, size_t *pargz_len)); 607 char **pargz, size_t * pargz_len));
604 608
605static error_t 609static error_t
606argz_create_sep (str, delim, pargz, pargz_len) 610argz_create_sep (str, delim, pargz, pargz_len)
@@ -618,7 +622,7 @@ argz_create_sep (str, delim, pargz, pargz_len)
618 622
619 /* Make a copy of STR, but replacing each occurence of 623 /* Make a copy of STR, but replacing each occurence of
620 DELIM with '\0'. */ 624 DELIM with '\0'. */
621 argz_len = 1+ LT_STRLEN (str); 625 argz_len = 1 + LT_STRLEN (str);
622 if (argz_len) 626 if (argz_len)
623 { 627 {
624 const char *p; 628 const char *p;
@@ -626,22 +630,22 @@ argz_create_sep (str, delim, pargz, pargz_len)
626 630
627 argz = LT_DLMALLOC (char, argz_len); 631 argz = LT_DLMALLOC (char, argz_len);
628 if (!argz) 632 if (!argz)
629 return ENOMEM; 633 return ENOMEM;
630 634
631 for (p = str, q = argz; *p != LT_EOS_CHAR; ++p) 635 for (p = str, q = argz; *p != LT_EOS_CHAR; ++p)
632 { 636 {
633 if (*p == delim) 637 if (*p == delim)
634 { 638 {
635 /* Ignore leading delimiters, and fold consecutive 639 /* Ignore leading delimiters, and fold consecutive
636 delimiters in STR into a single '\0' in ARGZ. */ 640 delimiters in STR into a single '\0' in ARGZ. */
637 if ((q > argz) && (q[-1] != LT_EOS_CHAR)) 641 if ((q > argz) && (q[-1] != LT_EOS_CHAR))
638 *q++ = LT_EOS_CHAR; 642 *q++ = LT_EOS_CHAR;
639 else 643 else
640 --argz_len; 644 --argz_len;
641 } 645 }
642 else 646 else
643 *q++ = *p; 647 *q++ = *p;
644 } 648 }
645 /* Copy terminating LT_EOS_CHAR. */ 649 /* Copy terminating LT_EOS_CHAR. */
646 *q = *p; 650 *q = *p;
647 } 651 }
@@ -662,8 +666,8 @@ argz_create_sep (str, delim, pargz, pargz_len)
662#if ! HAVE_ARGZ_INSERT 666#if ! HAVE_ARGZ_INSERT
663# define argz_insert rpl_argz_insert 667# define argz_insert rpl_argz_insert
664 668
665static error_t argz_insert LT_PARAMS((char **pargz, size_t *pargz_len, 669static error_t argz_insert LT_PARAMS ((char **pargz, size_t * pargz_len,
666 char *before, const char *entry)); 670 char *before, const char *entry));
667 671
668static error_t 672static error_t
669argz_insert (pargz, pargz_len, before, entry) 673argz_insert (pargz, pargz_len, before, entry)
@@ -679,7 +683,7 @@ argz_insert (pargz, pargz_len, before, entry)
679 /* No BEFORE address indicates ENTRY should be inserted after the 683 /* No BEFORE address indicates ENTRY should be inserted after the
680 current last element. */ 684 current last element. */
681 if (!before) 685 if (!before)
682 return argz_append (pargz, pargz_len, entry, 1+ LT_STRLEN (entry)); 686 return argz_append (pargz, pargz_len, entry, 1 + LT_STRLEN (entry));
683 687
684 /* This probably indicates a programmer error, but to preserve 688 /* This probably indicates a programmer error, but to preserve
685 semantics, scan back to the start of an entry if BEFORE points 689 semantics, scan back to the start of an entry if BEFORE points
@@ -688,10 +692,10 @@ argz_insert (pargz, pargz_len, before, entry)
688 --before; 692 --before;
689 693
690 { 694 {
691 size_t entry_len = 1+ LT_STRLEN (entry); 695 size_t entry_len = 1 + LT_STRLEN (entry);
692 size_t argz_len = *pargz_len + entry_len; 696 size_t argz_len = *pargz_len + entry_len;
693 size_t offset = before - *pargz; 697 size_t offset = before - *pargz;
694 char *argz = LT_DLREALLOC (char, *pargz, argz_len); 698 char *argz = LT_DLREALLOC (char, *pargz, argz_len);
695 699
696 if (!argz) 700 if (!argz)
697 return ENOMEM; 701 return ENOMEM;
@@ -704,7 +708,7 @@ argz_insert (pargz, pargz_len, before, entry)
704 space at the end -- making room to copy ENTRY into the 708 space at the end -- making room to copy ENTRY into the
705 resulting gap. */ 709 resulting gap. */
706 memmove (before + entry_len, before, *pargz_len - offset); 710 memmove (before + entry_len, before, *pargz_len - offset);
707 memcpy (before, entry, entry_len); 711 memcpy (before, entry, entry_len);
708 712
709 /* Assign new values. */ 713 /* Assign new values. */
710 *pargz = argz; 714 *pargz = argz;
@@ -719,8 +723,8 @@ argz_insert (pargz, pargz_len, before, entry)
719#if ! HAVE_ARGZ_NEXT 723#if ! HAVE_ARGZ_NEXT
720# define argz_next rpl_argz_next 724# define argz_next rpl_argz_next
721 725
722static char *argz_next LT_PARAMS((char *argz, size_t argz_len, 726static char *argz_next LT_PARAMS ((char *argz, size_t argz_len,
723 const char *entry)); 727 const char *entry));
724 728
725static char * 729static char *
726argz_next (argz, argz_len, entry) 730argz_next (argz, argz_len, entry)
@@ -733,28 +737,28 @@ argz_next (argz, argz_len, entry)
733 if (entry) 737 if (entry)
734 { 738 {
735 /* Either ARGZ/ARGZ_LEN is empty, or ENTRY points into an address 739 /* Either ARGZ/ARGZ_LEN is empty, or ENTRY points into an address
736 within the ARGZ vector. */ 740 within the ARGZ vector. */
737 assert ((!argz && !argz_len) 741 assert ((!argz && !argz_len)
738 || ((argz <= entry) && (entry < (argz + argz_len)))); 742 || ((argz <= entry) && (entry < (argz + argz_len))));
739 743
740 /* Move to the char immediately after the terminating 744 /* Move to the char immediately after the terminating
741 '\0' of ENTRY. */ 745 '\0' of ENTRY. */
742 entry = 1+ strchr (entry, LT_EOS_CHAR); 746 entry = 1 + strchr (entry, LT_EOS_CHAR);
743 747
744 /* Return either the new ENTRY, or else NULL if ARGZ is 748 /* Return either the new ENTRY, or else NULL if ARGZ is
745 exhausted. */ 749 exhausted. */
746 return (entry >= argz + argz_len) ? 0 : (char *) entry; 750 return (entry >= argz + argz_len) ? 0 : (char *) entry;
747 } 751 }
748 else 752 else
749 { 753 {
750 /* This should probably be flagged as a programmer error, 754 /* This should probably be flagged as a programmer error,
751 since starting an argz_next loop with the iterator set 755 since starting an argz_next loop with the iterator set
752 to ARGZ is safer. To preserve semantics, handle the NULL 756 to ARGZ is safer. To preserve semantics, handle the NULL
753 case by returning the start of ARGZ (if any). */ 757 case by returning the start of ARGZ (if any). */
754 if (argz_len > 0) 758 if (argz_len > 0)
755 return argz; 759 return argz;
756 else 760 else
757 return 0; 761 return 0;
758 } 762 }
759} 763}
760#endif /* !HAVE_ARGZ_NEXT */ 764#endif /* !HAVE_ARGZ_NEXT */
@@ -764,8 +768,7 @@ argz_next (argz, argz_len, entry)
764#if ! HAVE_ARGZ_STRINGIFY 768#if ! HAVE_ARGZ_STRINGIFY
765# define argz_stringify rpl_argz_stringify 769# define argz_stringify rpl_argz_stringify
766 770
767static void argz_stringify LT_PARAMS((char *argz, size_t argz_len, 771static void argz_stringify LT_PARAMS ((char *argz, size_t argz_len, int sep));
768 int sep));
769 772
770static void 773static void
771argz_stringify (argz, argz_len, sep) 774argz_stringify (argz, argz_len, sep)
@@ -777,68 +780,69 @@ argz_stringify (argz, argz_len, sep)
777 780
778 if (sep) 781 if (sep)
779 { 782 {
780 --argz_len; /* don't stringify the terminating EOS */ 783 --argz_len; /* don't stringify the terminating EOS */
781 while (--argz_len > 0) 784 while (--argz_len > 0)
782 { 785 {
783 if (argz[argz_len] == LT_EOS_CHAR) 786 if (argz[argz_len] == LT_EOS_CHAR)
784 argz[argz_len] = sep; 787 argz[argz_len] = sep;
785 } 788 }
786 } 789 }
787} 790}
788#endif /* !HAVE_ARGZ_STRINGIFY */ 791#endif /* !HAVE_ARGZ_STRINGIFY */
792
789 793
790 794
791 795
792
793/* --- TYPE DEFINITIONS -- */ 796/* --- TYPE DEFINITIONS -- */
794 797
795 798
796/* This type is used for the array of caller data sets in each handler. */ 799/* This type is used for the array of caller data sets in each handler. */
797typedef struct { 800typedef struct
798 lt_dlcaller_id key; 801{
799 lt_ptr data; 802 lt_dlcaller_id key;
803 lt_ptr data;
800} lt_caller_data; 804} lt_caller_data;
805
801 806
802 807
803 808
804
805/* --- OPAQUE STRUCTURES DECLARED IN LTDL.H --- */ 809/* --- OPAQUE STRUCTURES DECLARED IN LTDL.H --- */
806 810
807 811
808/* Extract the diagnostic strings from the error table macro in the same 812/* Extract the diagnostic strings from the error table macro in the same
809 order as the enumerated indices in ltdl.h. */ 813 order as the enumerated indices in ltdl.h. */
810 814
811static const char *lt_dlerror_strings[] = 815static const char *lt_dlerror_strings[] = {
812 {
813#define LT_ERROR(name, diagnostic) (diagnostic), 816#define LT_ERROR(name, diagnostic) (diagnostic),
814 lt_dlerror_table 817 lt_dlerror_table
815#undef LT_ERROR 818#undef LT_ERROR
816 819 0
817 0 820};
818 };
819 821
820/* This structure is used for the list of registered loaders. */ 822/* This structure is used for the list of registered loaders. */
821struct lt_dlloader { 823struct lt_dlloader
822 struct lt_dlloader *next; 824{
823 const char *loader_name; /* identifying name for each loader */ 825 struct lt_dlloader *next;
824 const char *sym_prefix; /* prefix for symbols */ 826 const char *loader_name; /* identifying name for each loader */
825 lt_module_open *module_open; 827 const char *sym_prefix; /* prefix for symbols */
826 lt_module_close *module_close; 828 lt_module_open *module_open;
827 lt_find_sym *find_sym; 829 lt_module_close *module_close;
828 lt_dlloader_exit *dlloader_exit; 830 lt_find_sym *find_sym;
829 lt_user_data dlloader_data; 831 lt_dlloader_exit *dlloader_exit;
832 lt_user_data dlloader_data;
830}; 833};
831 834
832struct lt_dlhandle_struct { 835struct lt_dlhandle_struct
833 struct lt_dlhandle_struct *next; 836{
834 lt_dlloader *loader; /* dlopening interface */ 837 struct lt_dlhandle_struct *next;
835 lt_dlinfo info; 838 lt_dlloader *loader; /* dlopening interface */
836 int depcount; /* number of dependencies */ 839 lt_dlinfo info;
837 lt_dlhandle *deplibs; /* dependencies */ 840 int depcount; /* number of dependencies */
838 lt_module module; /* system module handle */ 841 lt_dlhandle *deplibs; /* dependencies */
839 lt_ptr system; /* system specific data */ 842 lt_module module; /* system module handle */
840 lt_caller_data *caller_data; /* per caller associated data */ 843 lt_ptr system; /* system specific data */
841 int flags; /* various boolean stats */ 844 lt_caller_data *caller_data; /* per caller associated data */
845 int flags; /* various boolean stats */
842}; 846};
843 847
844/* Various boolean flags can be stored in the flags field of an 848/* Various boolean flags can be stored in the flags field of an
@@ -854,18 +858,18 @@ struct lt_dlhandle_struct {
854 858
855#define LT_DLSTRERROR(name) lt_dlerror_strings[LT_CONC(LT_ERROR_,name)] 859#define LT_DLSTRERROR(name) lt_dlerror_strings[LT_CONC(LT_ERROR_,name)]
856 860
857static const char objdir[] = LTDL_OBJDIR; 861static const char objdir[] = LTDL_OBJDIR;
858static const char archive_ext[] = LTDL_ARCHIVE_EXT; 862static const char archive_ext[] = LTDL_ARCHIVE_EXT;
859#ifdef LTDL_SHLIB_EXT 863#ifdef LTDL_SHLIB_EXT
860static const char shlib_ext[] = LTDL_SHLIB_EXT; 864static const char shlib_ext[] = LTDL_SHLIB_EXT;
861#endif 865#endif
862#ifdef LTDL_SYSSEARCHPATH 866#ifdef LTDL_SYSSEARCHPATH
863static const char sys_search_path[] = LTDL_SYSSEARCHPATH; 867static const char sys_search_path[] = LTDL_SYSSEARCHPATH;
864#endif 868#endif
869
865 870
866 871
867 872
868
869/* --- MUTEX LOCKING --- */ 873/* --- MUTEX LOCKING --- */
870 874
871 875
@@ -891,11 +895,11 @@ static const char sys_search_path[] = LTDL_SYSSEARCHPATH;
891 895
892/* The mutex functions stored here are global, and are necessarily the 896/* The mutex functions stored here are global, and are necessarily the
893 same for all threads that wish to share access to libltdl. */ 897 same for all threads that wish to share access to libltdl. */
894static lt_dlmutex_lock *lt_dlmutex_lock_func = 0; 898static lt_dlmutex_lock *lt_dlmutex_lock_func = 0;
895static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0; 899static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0;
896static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0; 900static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0;
897static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0; 901static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0;
898static const char *lt_dllast_error = 0; 902static const char *lt_dllast_error = 0;
899 903
900 904
901/* Either set or reset the mutex functions. Either all the arguments must 905/* Either set or reset the mutex functions. Either all the arguments must
@@ -910,7 +914,7 @@ lt_dlmutex_register (lock, unlock, seterror, geterror)
910 lt_dlmutex_geterror *geterror; 914 lt_dlmutex_geterror *geterror;
911{ 915{
912 lt_dlmutex_unlock *old_unlock = unlock; 916 lt_dlmutex_unlock *old_unlock = unlock;
913 int errors = 0; 917 int errors = 0;
914 918
915 /* Lock using the old lock() callback, if any. */ 919 /* Lock using the old lock() callback, if any. */
916 LT_DLMUTEX_LOCK (); 920 LT_DLMUTEX_LOCK ();
@@ -918,8 +922,8 @@ lt_dlmutex_register (lock, unlock, seterror, geterror)
918 if ((lock && unlock && seterror && geterror) 922 if ((lock && unlock && seterror && geterror)
919 || !(lock || unlock || seterror || geterror)) 923 || !(lock || unlock || seterror || geterror))
920 { 924 {
921 lt_dlmutex_lock_func = lock; 925 lt_dlmutex_lock_func = lock;
922 lt_dlmutex_unlock_func = unlock; 926 lt_dlmutex_unlock_func = unlock;
923 lt_dlmutex_geterror_func = geterror; 927 lt_dlmutex_geterror_func = geterror;
924 } 928 }
925 else 929 else
@@ -937,23 +941,23 @@ lt_dlmutex_register (lock, unlock, seterror, geterror)
937 this function. */ 941 this function. */
938 return errors; 942 return errors;
939} 943}
944
940 945
941 946
942 947
943
944/* --- ERROR HANDLING --- */ 948/* --- ERROR HANDLING --- */
945 949
946 950
947static const char **user_error_strings = 0; 951static const char **user_error_strings = 0;
948static int errorcount = LT_ERROR_MAX; 952static int errorcount = LT_ERROR_MAX;
949 953
950int 954int
951lt_dladderror (diagnostic) 955lt_dladderror (diagnostic)
952 const char *diagnostic; 956 const char *diagnostic;
953{ 957{
954 int errindex = 0; 958 int errindex = 0;
955 int result = -1; 959 int result = -1;
956 const char **temp = (const char **) 0; 960 const char **temp = (const char **) 0;
957 961
958 assert (diagnostic); 962 assert (diagnostic);
959 963
@@ -963,9 +967,9 @@ lt_dladderror (diagnostic)
963 temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex); 967 temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex);
964 if (temp) 968 if (temp)
965 { 969 {
966 user_error_strings = temp; 970 user_error_strings = temp;
967 user_error_strings[errindex] = diagnostic; 971 user_error_strings[errindex] = diagnostic;
968 result = errorcount++; 972 result = errorcount++;
969 } 973 }
970 974
971 LT_DLMUTEX_UNLOCK (); 975 LT_DLMUTEX_UNLOCK ();
@@ -977,7 +981,7 @@ int
977lt_dlseterror (errindex) 981lt_dlseterror (errindex)
978 int errindex; 982 int errindex;
979{ 983{
980 int errors = 0; 984 int errors = 0;
981 985
982 LT_DLMUTEX_LOCK (); 986 LT_DLMUTEX_LOCK ();
983 987
@@ -1033,10 +1037,10 @@ lt_estrdup (str)
1033 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); 1037 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1034 return copy; 1038 return copy;
1035} 1039}
1040
1036 1041
1037 1042
1038 1043
1039
1040/* --- DLOPEN() INTERFACE LOADER --- */ 1044/* --- DLOPEN() INTERFACE LOADER --- */
1041 1045
1042 1046
@@ -1087,7 +1091,7 @@ sys_dl_open (loader_data, filename)
1087 lt_user_data loader_data; 1091 lt_user_data loader_data;
1088 const char *filename; 1092 const char *filename;
1089{ 1093{
1090 lt_module module = dlopen (filename, LT_LAZY_OR_NOW); 1094 lt_module module = dlopen (filename, LT_LAZY_OR_NOW);
1091 1095
1092 if (!module) 1096 if (!module)
1093 { 1097 {
@@ -1129,20 +1133,20 @@ sys_dl_sym (loader_data, module, symbol)
1129 return address; 1133 return address;
1130} 1134}
1131 1135
1132static struct lt_user_dlloader sys_dl = 1136static struct lt_user_dlloader sys_dl = {
1133 {
1134# ifdef NEED_USCORE 1137# ifdef NEED_USCORE
1135 "_", 1138 "_",
1136# else 1139# else
1137 0, 1140 0,
1138# endif 1141# endif
1139 sys_dl_open, sys_dl_close, sys_dl_sym, 0, 0 }; 1142 sys_dl_open, sys_dl_close, sys_dl_sym, 0, 0
1143};
1140 1144
1141 1145
1142#endif /* HAVE_LIBDL */ 1146#endif /* HAVE_LIBDL */
1147
1143 1148
1144 1149
1145
1146/* --- SHL_LOAD() INTERFACE LOADER --- */ 1150/* --- SHL_LOAD() INTERFACE LOADER --- */
1147 1151
1148#if HAVE_SHL_LOAD 1152#if HAVE_SHL_LOAD
@@ -1220,9 +1224,9 @@ sys_shl_open (loader_data, filename)
1220 module = shl_load (filename, LT_BIND_FLAGS, 0L); 1224 module = shl_load (filename, LT_BIND_FLAGS, 0L);
1221 1225
1222 if (!module) 1226 if (!module)
1223 { 1227 {
1224 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); 1228 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));
1225 } 1229 }
1226 } 1230 }
1227 1231
1228 return module; 1232 return module;
@@ -1254,15 +1258,16 @@ sys_shl_sym (loader_data, module, symbol)
1254 1258
1255 /* sys_shl_open should never return a NULL module handle */ 1259 /* sys_shl_open should never return a NULL module handle */
1256 if (module == (lt_module) 0) 1260 if (module == (lt_module) 0)
1257 { 1261 {
1258 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); 1262 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));
1259 } 1263 }
1260 else if (!shl_findsym((shl_t*) &module, symbol, TYPE_UNDEFINED, &address)) 1264 else
1265 if (!shl_findsym ((shl_t *) & module, symbol, TYPE_UNDEFINED, &address))
1261 { 1266 {
1262 if (!address) 1267 if (!address)
1263 { 1268 {
1264 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); 1269 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
1265 } 1270 }
1266 } 1271 }
1267 1272
1268 return address; 1273 return address;
@@ -1273,10 +1278,10 @@ static struct lt_user_dlloader sys_shl = {
1273}; 1278};
1274 1279
1275#endif /* HAVE_SHL_LOAD */ 1280#endif /* HAVE_SHL_LOAD */
1281
1276 1282
1277 1283
1278 1284
1279
1280/* --- LOADLIBRARY() INTERFACE LOADER --- */ 1285/* --- LOADLIBRARY() INTERFACE LOADER --- */
1281 1286
1282#ifdef __WINDOWS__ 1287#ifdef __WINDOWS__
@@ -1293,12 +1298,12 @@ sys_wll_open (loader_data, filename)
1293 lt_user_data loader_data; 1298 lt_user_data loader_data;
1294 const char *filename; 1299 const char *filename;
1295{ 1300{
1296 lt_dlhandle cur; 1301 lt_dlhandle cur;
1297 lt_module module = 0; 1302 lt_module module = 0;
1298 const char *errormsg = 0; 1303 const char *errormsg = 0;
1299 char *searchname = 0; 1304 char *searchname = 0;
1300 char *ext; 1305 char *ext;
1301 char self_name_buf[MAX_PATH]; 1306 char self_name_buf[MAX_PATH];
1302 1307
1303 if (!filename) 1308 if (!filename)
1304 { 1309 {
@@ -1320,10 +1325,10 @@ sys_wll_open (loader_data, filename)
1320 else 1325 else
1321 { 1326 {
1322 /* Append a `.' to stop Windows from adding an 1327 /* Append a `.' to stop Windows from adding an
1323 implicit `.dll' extension. */ 1328 implicit `.dll' extension. */
1324 searchname = LT_EMALLOC (char, 2+ LT_STRLEN (filename)); 1329 searchname = LT_EMALLOC (char, 2 + LT_STRLEN (filename));
1325 if (searchname) 1330 if (searchname)
1326 sprintf (searchname, "%s.", filename); 1331 sprintf (searchname, "%s.", filename);
1327 } 1332 }
1328 if (!searchname) 1333 if (!searchname)
1329 return 0; 1334 return 0;
@@ -1331,8 +1336,8 @@ sys_wll_open (loader_data, filename)
1331#if __CYGWIN__ 1336#if __CYGWIN__
1332 { 1337 {
1333 char wpath[MAX_PATH]; 1338 char wpath[MAX_PATH];
1334 cygwin_conv_to_full_win32_path(searchname, wpath); 1339 cygwin_conv_to_full_win32_path (searchname, wpath);
1335 module = LoadLibrary(wpath); 1340 module = LoadLibrary (wpath);
1336 } 1341 }
1337#else 1342#else
1338 module = LoadLibrary (searchname); 1343 module = LoadLibrary (searchname);
@@ -1352,18 +1357,18 @@ sys_wll_open (loader_data, filename)
1352 while (cur) 1357 while (cur)
1353 { 1358 {
1354 if (!cur->module) 1359 if (!cur->module)
1355 { 1360 {
1356 cur = 0; 1361 cur = 0;
1357 break; 1362 break;
1358 } 1363 }
1359 1364
1360 if (cur->module == module) 1365 if (cur->module == module)
1361 { 1366 {
1362 break; 1367 break;
1363 } 1368 }
1364 1369
1365 cur = cur->next; 1370 cur = cur->next;
1366 } 1371 }
1367 LT_DLMUTEX_UNLOCK (); 1372 LT_DLMUTEX_UNLOCK ();
1368 1373
1369 if (cur || !module) 1374 if (cur || !module)
@@ -1380,9 +1385,9 @@ sys_wll_close (loader_data, module)
1380 lt_user_data loader_data; 1385 lt_user_data loader_data;
1381 lt_module module; 1386 lt_module module;
1382{ 1387{
1383 int errors = 0; 1388 int errors = 0;
1384 1389
1385 if (FreeLibrary(module) == 0) 1390 if (FreeLibrary (module) == 0)
1386 { 1391 {
1387 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); 1392 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));
1388 ++errors; 1393 ++errors;
@@ -1397,7 +1402,7 @@ sys_wll_sym (loader_data, module, symbol)
1397 lt_module module; 1402 lt_module module;
1398 const char *symbol; 1403 const char *symbol;
1399{ 1404{
1400 lt_ptr address = GetProcAddress (module, symbol); 1405 lt_ptr address = GetProcAddress (module, symbol);
1401 1406
1402 if (!address) 1407 if (!address)
1403 { 1408 {
@@ -1412,10 +1417,10 @@ static struct lt_user_dlloader sys_wll = {
1412}; 1417};
1413 1418
1414#endif /* __WINDOWS__ */ 1419#endif /* __WINDOWS__ */
1420
1415 1421
1416 1422
1417 1423
1418
1419/* --- LOAD_ADD_ON() INTERFACE LOADER --- */ 1424/* --- LOAD_ADD_ON() INTERFACE LOADER --- */
1420 1425
1421 1426
@@ -1441,7 +1446,7 @@ sys_bedl_open (loader_data, filename)
1441 image_info info; 1446 image_info info;
1442 int32 cookie = 0; 1447 int32 cookie = 0;
1443 if (get_next_image_info (0, &cookie, &info) == B_OK) 1448 if (get_next_image_info (0, &cookie, &info) == B_OK)
1444 image = load_add_on (info.name); 1449 image = load_add_on (info.name);
1445 } 1450 }
1446 1451
1447 if (image <= 0) 1452 if (image <= 0)
@@ -1492,10 +1497,10 @@ static struct lt_user_dlloader sys_bedl = {
1492}; 1497};
1493 1498
1494#endif /* __BEOS__ */ 1499#endif /* __BEOS__ */
1500
1495 1501
1496 1502
1497 1503
1498
1499/* --- DLD_LINK() INTERFACE LOADER --- */ 1504/* --- DLD_LINK() INTERFACE LOADER --- */
1500 1505
1501 1506
@@ -1531,7 +1536,7 @@ sys_dld_close (loader_data, module)
1531{ 1536{
1532 int errors = 0; 1537 int errors = 0;
1533 1538
1534 if (dld_unlink_by_file ((char*)(module), 1) != 0) 1539 if (dld_unlink_by_file ((char *) (module), 1) != 0)
1535 { 1540 {
1536 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); 1541 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));
1537 ++errors; 1542 ++errors;
@@ -1584,10 +1589,11 @@ static struct lt_user_dlloader sys_dld = {
1584# define ENUM_DYLD_BOOL 1589# define ENUM_DYLD_BOOL
1585# undef FALSE 1590# undef FALSE
1586# undef TRUE 1591# undef TRUE
1587 enum DYLD_BOOL { 1592enum DYLD_BOOL
1588 FALSE, 1593{
1589 TRUE 1594 FALSE,
1590 }; 1595 TRUE
1596};
1591#endif 1597#endif
1592#ifndef LC_REQ_DYLD 1598#ifndef LC_REQ_DYLD
1593# define LC_REQ_DYLD 0x80000000 1599# define LC_REQ_DYLD 0x80000000
@@ -1595,10 +1601,18 @@ static struct lt_user_dlloader sys_dld = {
1595#ifndef LC_LOAD_WEAK_DYLIB 1601#ifndef LC_LOAD_WEAK_DYLIB
1596# define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) 1602# define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
1597#endif 1603#endif
1598static const struct mach_header * (*ltdl_NSAddImage)(const char *image_name, unsigned long options) = 0; 1604static const struct mach_header *(*ltdl_NSAddImage) (const char *image_name,
1599static NSSymbol (*ltdl_NSLookupSymbolInImage)(const struct mach_header *image,const char *symbolName, unsigned long options) = 0; 1605 unsigned long options) =
1600static enum DYLD_BOOL (*ltdl_NSIsSymbolNameDefinedInImage)(const struct mach_header *image, const char *symbolName) = 0; 1606 0;
1601static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0; 1607static NSSymbol (*ltdl_NSLookupSymbolInImage) (const struct mach_header *
1608 image, const char *symbolName,
1609 unsigned long options) = 0;
1610static enum DYLD_BOOL (*ltdl_NSIsSymbolNameDefinedInImage) (const struct
1611 mach_header *
1612 image,
1613 const char
1614 *symbolName) = 0;
1615static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic) (NSModule module) = 0;
1602 1616
1603#ifndef NSADDIMAGE_OPTION_NONE 1617#ifndef NSADDIMAGE_OPTION_NONE
1604#define NSADDIMAGE_OPTION_NONE 0x0 1618#define NSADDIMAGE_OPTION_NONE 0x0
@@ -1630,144 +1644,170 @@ static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0;
1630 1644
1631 1645
1632static const char * 1646static const char *
1633lt_int_dyld_error(othererror) 1647lt_int_dyld_error (othererror)
1634 char* othererror; 1648 char *othererror;
1635{ 1649{
1636/* return the dyld error string, or the passed in error string if none */ 1650/* return the dyld error string, or the passed in error string if none */
1637 NSLinkEditErrors ler; 1651 NSLinkEditErrors ler;
1638 int lerno; 1652 int lerno;
1639 const char *errstr; 1653 const char *errstr;
1640 const char *file; 1654 const char *file;
1641 NSLinkEditError(&ler,&lerno,&file,&errstr); 1655 NSLinkEditError (&ler, &lerno, &file, &errstr);
1642 if (!errstr || !strlen(errstr)) errstr = othererror; 1656 if (!errstr || !strlen (errstr))
1643 return errstr; 1657 errstr = othererror;
1658 return errstr;
1644} 1659}
1645 1660
1646static const struct mach_header * 1661static const struct mach_header *
1647lt_int_dyld_get_mach_header_from_nsmodule(module) 1662lt_int_dyld_get_mach_header_from_nsmodule (module)
1648 NSModule module; 1663 NSModule module;
1649{ 1664{
1650/* There should probably be an apple dyld api for this */ 1665/* There should probably be an apple dyld api for this */
1651 int i=_dyld_image_count(); 1666 int i = _dyld_image_count ();
1652 int j; 1667 int j;
1653 const char *modname=NSNameOfModule(module); 1668 const char *modname = NSNameOfModule (module);
1654 const struct mach_header *mh=NULL; 1669 const struct mach_header *mh = NULL;
1655 if (!modname) return NULL; 1670 if (!modname)
1656 for (j = 0; j < i; j++) 1671 return NULL;
1657 { 1672 for (j = 0; j < i; j++)
1658 if (!strcmp(_dyld_get_image_name(j),modname)) 1673 {
1659 { 1674 if (!strcmp (_dyld_get_image_name (j), modname))
1660 mh=_dyld_get_image_header(j); 1675 {
1661 break; 1676 mh = _dyld_get_image_header (j);
1662 } 1677 break;
1663 } 1678 }
1664 return mh; 1679 }
1680 return mh;
1665} 1681}
1666 1682
1667static const char* lt_int_dyld_lib_install_name(mh) 1683static const char *
1668 const struct mach_header *mh; 1684lt_int_dyld_lib_install_name (mh)
1685 const struct mach_header *mh;
1669{ 1686{
1670/* NSAddImage is also used to get the loaded image, but it only works if the lib 1687/* NSAddImage is also used to get the loaded image, but it only works if the lib
1671 is installed, for uninstalled libs we need to check the install_names against 1688 is installed, for uninstalled libs we need to check the install_names against
1672 each other. Note that this is still broken if DYLD_IMAGE_SUFFIX is set and a 1689 each other. Note that this is still broken if DYLD_IMAGE_SUFFIX is set and a
1673 different lib was loaded as a result 1690 different lib was loaded as a result
1674*/ 1691*/
1675 int j; 1692 int j;
1676 struct load_command *lc; 1693 struct load_command *lc;
1677 unsigned long offset = sizeof(struct mach_header); 1694 unsigned long offset = sizeof (struct mach_header);
1678 const char* retStr=NULL; 1695 const char *retStr = NULL;
1679 for (j = 0; j < mh->ncmds; j++) 1696 for (j = 0; j < mh->ncmds; j++)
1680 { 1697 {
1681 lc = (struct load_command*)(((unsigned long)mh) + offset); 1698 lc = (struct load_command *) (((unsigned long) mh) + offset);
1682 if (LC_ID_DYLIB == lc->cmd) 1699 if (LC_ID_DYLIB == lc->cmd)
1683 { 1700 {
1684 retStr=(char*)(((struct dylib_command*)lc)->dylib.name.offset + 1701 retStr =
1685 (unsigned long)lc); 1702 (char *) (((struct dylib_command *) lc)->dylib.name.offset +
1686 } 1703 (unsigned long) lc);
1687 offset += lc->cmdsize; 1704 }
1688 } 1705 offset += lc->cmdsize;
1689 return retStr; 1706 }
1707 return retStr;
1690} 1708}
1691 1709
1692static const struct mach_header * 1710static const struct mach_header *
1693lt_int_dyld_match_loaded_lib_by_install_name(const char *name) 1711lt_int_dyld_match_loaded_lib_by_install_name (const char *name)
1694{ 1712{
1695 int i=_dyld_image_count(); 1713 int i = _dyld_image_count ();
1696 int j; 1714 int j;
1697 const struct mach_header *mh=NULL; 1715 const struct mach_header *mh = NULL;
1698 const char *id=NULL; 1716 const char *id = NULL;
1699 for (j = 0; j < i; j++) 1717 for (j = 0; j < i; j++)
1700 { 1718 {
1701 id=lt_int_dyld_lib_install_name(_dyld_get_image_header(j)); 1719 id = lt_int_dyld_lib_install_name (_dyld_get_image_header (j));
1702 if ((id) && (!strcmp(id,name))) 1720 if ((id) && (!strcmp (id, name)))
1703 { 1721 {
1704 mh=_dyld_get_image_header(j); 1722 mh = _dyld_get_image_header (j);
1705 break; 1723 break;
1706 } 1724 }
1707 } 1725 }
1708 return mh; 1726 return mh;
1709} 1727}
1710 1728
1711static NSSymbol 1729static NSSymbol
1712lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh) 1730lt_int_dyld_NSlookupSymbolInLinkedLibs (symbol, mh)
1713 const char *symbol; 1731 const char *symbol;
1714 const struct mach_header *mh; 1732 const struct mach_header *mh;
1715{ 1733{
1716 /* Safe to assume our mh is good */ 1734 /* Safe to assume our mh is good */
1717 int j; 1735 int j;
1718 struct load_command *lc; 1736 struct load_command *lc;
1719 unsigned long offset = sizeof(struct mach_header); 1737 unsigned long offset = sizeof (struct mach_header);
1720 NSSymbol retSym = 0; 1738 NSSymbol retSym = 0;
1721 const struct mach_header *mh1; 1739 const struct mach_header *mh1;
1722 if ((ltdl_NSLookupSymbolInImage) && NSIsSymbolNameDefined(symbol) ) 1740 if ((ltdl_NSLookupSymbolInImage) && NSIsSymbolNameDefined (symbol))
1723 { 1741 {
1724 for (j = 0; j < mh->ncmds; j++) 1742 for (j = 0; j < mh->ncmds; j++)
1725 { 1743 {
1726 lc = (struct load_command*)(((unsigned long)mh) + offset); 1744 lc = (struct load_command *) (((unsigned long) mh) + offset);
1727 if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) 1745 if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
1728 { 1746 {
1729 mh1=lt_int_dyld_match_loaded_lib_by_install_name((char*)(((struct dylib_command*)lc)->dylib.name.offset + 1747 mh1 =
1730 (unsigned long)lc)); 1748 lt_int_dyld_match_loaded_lib_by_install_name ((char
1731 if (!mh1) 1749 *) (((struct
1732 { 1750 dylib_command
1733 /* Maybe NSAddImage can find it */ 1751 *) lc)->
1734 mh1=ltdl_NSAddImage((char*)(((struct dylib_command*)lc)->dylib.name.offset + 1752 dylib.name.
1735 (unsigned long)lc), 1753 offset +
1736 NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED + 1754 (unsigned
1737 NSADDIMAGE_OPTION_WITH_SEARCHING + 1755 long)
1738 NSADDIMAGE_OPTION_RETURN_ON_ERROR ); 1756 lc));
1739 } 1757 if (!mh1)
1740 if (mh1) 1758 {
1741 { 1759 /* Maybe NSAddImage can find it */
1742 retSym = ltdl_NSLookupSymbolInImage(mh1, 1760 mh1 =
1743 symbol, 1761 ltdl_NSAddImage ((char *) (((struct dylib_command *) lc)->
1744 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 1762 dylib.name.offset +
1745 | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 1763 (unsigned long) lc),
1746 ); 1764 NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED +
1747 if (retSym) break; 1765 NSADDIMAGE_OPTION_WITH_SEARCHING +
1748 } 1766 NSADDIMAGE_OPTION_RETURN_ON_ERROR);
1749 } 1767 }
1750 offset += lc->cmdsize; 1768 if (mh1)
1751 } 1769 {
1752 } 1770 retSym = ltdl_NSLookupSymbolInImage (mh1,
1753 return retSym; 1771 symbol,
1772 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW
1773 |
1774 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
1775 if (retSym)
1776 break;
1777 }
1778 }
1779 offset += lc->cmdsize;
1780 }
1781 }
1782 return retSym;
1754} 1783}
1755 1784
1756static int 1785static int
1757sys_dyld_init() 1786sys_dyld_init ()
1758{ 1787{
1759 int retCode = 0; 1788 int retCode = 0;
1760 int err = 0; 1789 int err = 0;
1761 if (!_dyld_present()) { 1790 if (!_dyld_present ())
1762 retCode=1; 1791 {
1763 } 1792 retCode = 1;
1764 else { 1793 }
1765 err = _dyld_func_lookup("__dyld_NSAddImage",(unsigned long*)&ltdl_NSAddImage); 1794 else
1766 err = _dyld_func_lookup("__dyld_NSLookupSymbolInImage",(unsigned long*)&ltdl_NSLookupSymbolInImage); 1795 {
1767 err = _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",(unsigned long*)&ltdl_NSIsSymbolNameDefinedInImage); 1796 err =
1768 err = _dyld_func_lookup("__dyld_NSMakePrivateModulePublic",(unsigned long*)&ltdl_NSMakePrivateModulePublic); 1797 _dyld_func_lookup ("__dyld_NSAddImage",
1769 } 1798 (unsigned long *) &ltdl_NSAddImage);
1770 return retCode; 1799 err =
1800 _dyld_func_lookup ("__dyld_NSLookupSymbolInImage",
1801 (unsigned long *) &ltdl_NSLookupSymbolInImage);
1802 err =
1803 _dyld_func_lookup ("__dyld_NSIsSymbolNameDefinedInImage",
1804 (unsigned long *)
1805 &ltdl_NSIsSymbolNameDefinedInImage);
1806 err =
1807 _dyld_func_lookup ("__dyld_NSMakePrivateModulePublic",
1808 (unsigned long *) &ltdl_NSMakePrivateModulePublic);
1809 }
1810 return retCode;
1771} 1811}
1772 1812
1773static lt_module 1813static lt_module
@@ -1775,35 +1815,38 @@ sys_dyld_open (loader_data, filename)
1775 lt_user_data loader_data; 1815 lt_user_data loader_data;
1776 const char *filename; 1816 const char *filename;
1777{ 1817{
1778 lt_module module = 0; 1818 lt_module module = 0;
1779 NSObjectFileImage ofi = 0; 1819 NSObjectFileImage ofi = 0;
1780 NSObjectFileImageReturnCode ofirc; 1820 NSObjectFileImageReturnCode ofirc;
1781 1821
1782 if (!filename) 1822 if (!filename)
1783 return (lt_module)-1; 1823 return (lt_module) - 1;
1784 ofirc = NSCreateObjectFileImageFromFile(filename, &ofi); 1824 ofirc = NSCreateObjectFileImageFromFile (filename, &ofi);
1785 switch (ofirc) 1825 switch (ofirc)
1786 { 1826 {
1787 case NSObjectFileImageSuccess: 1827 case NSObjectFileImageSuccess:
1788 module = NSLinkModule(ofi, filename, 1828 module = NSLinkModule (ofi, filename,
1789 NSLINKMODULE_OPTION_RETURN_ON_ERROR 1829 NSLINKMODULE_OPTION_RETURN_ON_ERROR
1790 | NSLINKMODULE_OPTION_PRIVATE 1830 | NSLINKMODULE_OPTION_PRIVATE
1791 | NSLINKMODULE_OPTION_BINDNOW); 1831 | NSLINKMODULE_OPTION_BINDNOW);
1792 NSDestroyObjectFileImage(ofi); 1832 NSDestroyObjectFileImage (ofi);
1793 if (module) 1833 if (module)
1794 ltdl_NSMakePrivateModulePublic(module); 1834 ltdl_NSMakePrivateModulePublic (module);
1795 break; 1835 break;
1796 case NSObjectFileImageInappropriateFile: 1836 case NSObjectFileImageInappropriateFile:
1797 if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) 1837 if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage)
1798 { 1838 {
1799 module = (lt_module)ltdl_NSAddImage(filename, NSADDIMAGE_OPTION_RETURN_ON_ERROR); 1839 module =
1800 break; 1840 (lt_module) ltdl_NSAddImage (filename,
1801 } 1841 NSADDIMAGE_OPTION_RETURN_ON_ERROR);
1802 default: 1842 break;
1803 LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); 1843 }
1804 return 0; 1844 default:
1805 } 1845 LT_DLMUTEX_SETERROR (lt_int_dyld_error (LT_DLSTRERROR (CANNOT_OPEN)));
1806 if (!module) LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); 1846 return 0;
1847 }
1848 if (!module)
1849 LT_DLMUTEX_SETERROR (lt_int_dyld_error (LT_DLSTRERROR (CANNOT_OPEN)));
1807 return module; 1850 return module;
1808} 1851}
1809 1852
@@ -1812,43 +1855,45 @@ sys_dyld_close (loader_data, module)
1812 lt_user_data loader_data; 1855 lt_user_data loader_data;
1813 lt_module module; 1856 lt_module module;
1814{ 1857{
1815 int retCode = 0; 1858 int retCode = 0;
1816 int flags = 0; 1859 int flags = 0;
1817 if (module == (lt_module)-1) return 0; 1860 if (module == (lt_module) - 1)
1861 return 0;
1818#ifdef __BIG_ENDIAN__ 1862#ifdef __BIG_ENDIAN__
1819 if (((struct mach_header *)module)->magic == MH_MAGIC) 1863 if (((struct mach_header *) module)->magic == MH_MAGIC)
1820#else 1864#else
1821 if (((struct mach_header *)module)->magic == MH_CIGAM) 1865 if (((struct mach_header *) module)->magic == MH_CIGAM)
1822#endif 1866#endif
1823 { 1867 {
1824 LT_DLMUTEX_SETERROR("Can not close a dylib"); 1868 LT_DLMUTEX_SETERROR ("Can not close a dylib");
1825 retCode = 1; 1869 retCode = 1;
1826 } 1870 }
1827 else 1871 else
1828 { 1872 {
1829#if 1 1873#if 1
1830/* Currently, if a module contains c++ static destructors and it is unloaded, we 1874/* Currently, if a module contains c++ static destructors and it is unloaded, we
1831 get a segfault in atexit(), due to compiler and dynamic loader differences of 1875 get a segfault in atexit(), due to compiler and dynamic loader differences of
1832 opinion, this works around that. 1876 opinion, this works around that.
1833*/ 1877*/
1834 if ((const struct section *)NULL != 1878 if ((const struct section *) NULL !=
1835 getsectbynamefromheader(lt_int_dyld_get_mach_header_from_nsmodule(module), 1879 getsectbynamefromheader (lt_int_dyld_get_mach_header_from_nsmodule
1836 "__DATA","__mod_term_func")) 1880 (module), "__DATA", "__mod_term_func"))
1837 { 1881 {
1838 flags += NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; 1882 flags += NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
1839 } 1883 }
1840#endif 1884#endif
1841#ifdef __ppc__ 1885#ifdef __ppc__
1842 flags += NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; 1886 flags += NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
1843#endif 1887#endif
1844 if (!NSUnLinkModule(module,flags)) 1888 if (!NSUnLinkModule (module, flags))
1845 { 1889 {
1846 retCode=1; 1890 retCode = 1;
1847 LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_CLOSE))); 1891 LT_DLMUTEX_SETERROR (lt_int_dyld_error
1848 } 1892 (LT_DLSTRERROR (CANNOT_CLOSE)));
1849 } 1893 }
1850 1894 }
1851 return retCode; 1895
1896 return retCode;
1852} 1897}
1853 1898
1854static lt_ptr 1899static lt_ptr
@@ -1857,52 +1902,57 @@ sys_dyld_sym (loader_data, module, symbol)
1857 lt_module module; 1902 lt_module module;
1858 const char *symbol; 1903 const char *symbol;
1859{ 1904{
1860 lt_ptr address = 0; 1905 lt_ptr address = 0;
1861 NSSymbol *nssym = 0; 1906 NSSymbol *nssym = 0;
1862 void *unused; 1907 void *unused;
1863 const struct mach_header *mh=NULL; 1908 const struct mach_header *mh = NULL;
1864 char saveError[256] = "Symbol not found"; 1909 char saveError[256] = "Symbol not found";
1865 if (module == (lt_module)-1) 1910 if (module == (lt_module) - 1)
1866 { 1911 {
1867 _dyld_lookup_and_bind(symbol,(unsigned long*)&address,&unused); 1912 _dyld_lookup_and_bind (symbol, (unsigned long *) &address, &unused);
1868 return address; 1913 return address;
1869 } 1914 }
1870#ifdef __BIG_ENDIAN__ 1915#ifdef __BIG_ENDIAN__
1871 if (((struct mach_header *)module)->magic == MH_MAGIC) 1916 if (((struct mach_header *) module)->magic == MH_MAGIC)
1872#else 1917#else
1873 if (((struct mach_header *)module)->magic == MH_CIGAM) 1918 if (((struct mach_header *) module)->magic == MH_CIGAM)
1874#endif 1919#endif
1875 { 1920 {
1876 if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) 1921 if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage)
1877 { 1922 {
1878 mh=module; 1923 mh = module;
1879 if (ltdl_NSIsSymbolNameDefinedInImage((struct mach_header*)module,symbol)) 1924 if (ltdl_NSIsSymbolNameDefinedInImage
1880 { 1925 ((struct mach_header *) module, symbol))
1881 nssym = ltdl_NSLookupSymbolInImage((struct mach_header*)module, 1926 {
1882 symbol, 1927 nssym =
1883 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 1928 ltdl_NSLookupSymbolInImage ((struct mach_header *) module,
1884 | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 1929 symbol,
1885 ); 1930 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW
1886 } 1931 |
1887 } 1932 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
1888 1933 }
1889 } 1934 }
1890 else { 1935
1891 nssym = NSLookupSymbolInModule(module, symbol); 1936 }
1892 } 1937 else
1893 if (!nssym) 1938 {
1894 { 1939 nssym = NSLookupSymbolInModule (module, symbol);
1895 strncpy(saveError, lt_int_dyld_error(LT_DLSTRERROR(SYMBOL_NOT_FOUND)), 255); 1940 }
1896 saveError[255] = 0; 1941 if (!nssym)
1897 if (!mh) mh=lt_int_dyld_get_mach_header_from_nsmodule(module); 1942 {
1898 nssym = lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh); 1943 strncpy (saveError,
1899 } 1944 lt_int_dyld_error (LT_DLSTRERROR (SYMBOL_NOT_FOUND)), 255);
1900 if (!nssym) 1945 saveError[255] = 0;
1901 { 1946 if (!mh)
1902 LT_DLMUTEX_SETERROR (saveError); 1947 mh = lt_int_dyld_get_mach_header_from_nsmodule (module);
1903 return NULL; 1948 nssym = lt_int_dyld_NSlookupSymbolInLinkedLibs (symbol, mh);
1904 } 1949 }
1905 return NSAddressOfSymbol(nssym); 1950 if (!nssym)
1951 {
1952 LT_DLMUTEX_SETERROR (saveError);
1953 return NULL;
1954 }
1955 return NSAddressOfSymbol (nssym);
1906} 1956}
1907 1957
1908static struct lt_user_dlloader sys_dyld = 1958static struct lt_user_dlloader sys_dyld =
@@ -1910,8 +1960,8 @@ static struct lt_user_dlloader sys_dyld =
1910 1960
1911 1961
1912#endif /* HAVE_DYLD */ 1962#endif /* HAVE_DYLD */
1913
1914 1963
1964
1915/* --- DLPREOPEN() INTERFACE LOADER --- */ 1965/* --- DLPREOPEN() INTERFACE LOADER --- */
1916 1966
1917 1967
@@ -1919,12 +1969,12 @@ static struct lt_user_dlloader sys_dyld =
1919 1969
1920typedef struct lt_dlsymlists_t 1970typedef struct lt_dlsymlists_t
1921{ 1971{
1922 struct lt_dlsymlists_t *next; 1972 struct lt_dlsymlists_t *next;
1923 const lt_dlsymlist *syms; 1973 const lt_dlsymlist *syms;
1924} lt_dlsymlists_t; 1974} lt_dlsymlists_t;
1925 1975
1926static const lt_dlsymlist *default_preloaded_symbols = 0; 1976static const lt_dlsymlist *default_preloaded_symbols = 0;
1927static lt_dlsymlists_t *preloaded_symbols = 0; 1977static lt_dlsymlists_t *preloaded_symbols = 0;
1928 1978
1929static int 1979static int
1930presym_init (loader_data) 1980presym_init (loader_data)
@@ -1955,7 +2005,7 @@ presym_free_symlists ()
1955 lists = preloaded_symbols; 2005 lists = preloaded_symbols;
1956 while (lists) 2006 while (lists)
1957 { 2007 {
1958 lt_dlsymlists_t *tmp = lists; 2008 lt_dlsymlists_t *tmp = lists;
1959 2009
1960 lists = lists->next; 2010 lists = lists->next;
1961 LT_DLFREE (tmp); 2011 LT_DLFREE (tmp);
@@ -1981,7 +2031,7 @@ presym_add_symlist (preloaded)
1981{ 2031{
1982 lt_dlsymlists_t *tmp; 2032 lt_dlsymlists_t *tmp;
1983 lt_dlsymlists_t *lists; 2033 lt_dlsymlists_t *lists;
1984 int errors = 0; 2034 int errors = 0;
1985 2035
1986 LT_DLMUTEX_LOCK (); 2036 LT_DLMUTEX_LOCK ();
1987 2037
@@ -1989,16 +2039,16 @@ presym_add_symlist (preloaded)
1989 while (lists) 2039 while (lists)
1990 { 2040 {
1991 if (lists->syms == preloaded) 2041 if (lists->syms == preloaded)
1992 { 2042 {
1993 goto done; 2043 goto done;
1994 } 2044 }
1995 lists = lists->next; 2045 lists = lists->next;
1996 } 2046 }
1997 2047
1998 tmp = LT_EMALLOC (lt_dlsymlists_t, 1); 2048 tmp = LT_EMALLOC (lt_dlsymlists_t, 1);
1999 if (tmp) 2049 if (tmp)
2000 { 2050 {
2001 memset (tmp, 0, sizeof(lt_dlsymlists_t)); 2051 memset (tmp, 0, sizeof (lt_dlsymlists_t));
2002 tmp->syms = preloaded; 2052 tmp->syms = preloaded;
2003 tmp->next = preloaded_symbols; 2053 tmp->next = preloaded_symbols;
2004 preloaded_symbols = tmp; 2054 preloaded_symbols = tmp;
@@ -2008,7 +2058,7 @@ presym_add_symlist (preloaded)
2008 ++errors; 2058 ++errors;
2009 } 2059 }
2010 2060
2011 done: 2061done:
2012 LT_DLMUTEX_UNLOCK (); 2062 LT_DLMUTEX_UNLOCK ();
2013 return errors; 2063 return errors;
2014} 2064}
@@ -2019,7 +2069,7 @@ presym_open (loader_data, filename)
2019 const char *filename; 2069 const char *filename;
2020{ 2070{
2021 lt_dlsymlists_t *lists; 2071 lt_dlsymlists_t *lists;
2022 lt_module module = (lt_module) 0; 2072 lt_module module = (lt_module) 0;
2023 2073
2024 LT_DLMUTEX_LOCK (); 2074 LT_DLMUTEX_LOCK ();
2025 lists = preloaded_symbols; 2075 lists = preloaded_symbols;
@@ -2044,21 +2094,21 @@ presym_open (loader_data, filename)
2044 const lt_dlsymlist *syms = lists->syms; 2094 const lt_dlsymlist *syms = lists->syms;
2045 2095
2046 while (syms->name) 2096 while (syms->name)
2047 { 2097 {
2048 if (!syms->address && strcmp(syms->name, filename) == 0) 2098 if (!syms->address && strcmp (syms->name, filename) == 0)
2049 { 2099 {
2050 module = (lt_module) syms; 2100 module = (lt_module) syms;
2051 goto done; 2101 goto done;
2052 } 2102 }
2053 ++syms; 2103 ++syms;
2054 } 2104 }
2055 2105
2056 lists = lists->next; 2106 lists = lists->next;
2057 } 2107 }
2058 2108
2059 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); 2109 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
2060 2110
2061 done: 2111done:
2062 LT_DLMUTEX_UNLOCK (); 2112 LT_DLMUTEX_UNLOCK ();
2063 return module; 2113 return module;
2064} 2114}
@@ -2079,18 +2129,18 @@ presym_sym (loader_data, module, symbol)
2079 lt_module module; 2129 lt_module module;
2080 const char *symbol; 2130 const char *symbol;
2081{ 2131{
2082 lt_dlsymlist *syms = (lt_dlsymlist*) module; 2132 lt_dlsymlist *syms = (lt_dlsymlist *) module;
2083 2133
2084 ++syms; 2134 ++syms;
2085 while (syms->address) 2135 while (syms->address)
2086 { 2136 {
2087 if (strcmp(syms->name, symbol) == 0) 2137 if (strcmp (syms->name, symbol) == 0)
2088 { 2138 {
2089 return syms->address; 2139 return syms->address;
2090 } 2140 }
2091 2141
2092 ++syms; 2142 ++syms;
2093 } 2143 }
2094 2144
2095 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); 2145 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
2096 2146
@@ -2100,88 +2150,80 @@ presym_sym (loader_data, module, symbol)
2100static struct lt_user_dlloader presym = { 2150static struct lt_user_dlloader presym = {
2101 0, presym_open, presym_close, presym_sym, presym_exit, 0 2151 0, presym_open, presym_close, presym_sym, presym_exit, 0
2102}; 2152};
2153
2103 2154
2104 2155
2105 2156
2106 2157
2107
2108/* --- DYNAMIC MODULE LOADING --- */ 2158/* --- DYNAMIC MODULE LOADING --- */
2109 2159
2110 2160
2111/* The type of a function used at each iteration of foreach_dirinpath(). */ 2161/* The type of a function used at each iteration of foreach_dirinpath(). */
2112typedef int foreach_callback_func LT_PARAMS((char *filename, lt_ptr data1, 2162typedef int foreach_callback_func LT_PARAMS ((char *filename, lt_ptr data1,
2113 lt_ptr data2)); 2163 lt_ptr data2));
2114 2164
2115static int foreach_dirinpath LT_PARAMS((const char *search_path, 2165static int foreach_dirinpath LT_PARAMS ((const char *search_path,
2116 const char *base_name, 2166 const char *base_name,
2117 foreach_callback_func *func, 2167 foreach_callback_func * func,
2118 lt_ptr data1, lt_ptr data2)); 2168 lt_ptr data1, lt_ptr data2));
2119 2169
2120static int find_file_callback LT_PARAMS((char *filename, lt_ptr data, 2170static int find_file_callback LT_PARAMS ((char *filename, lt_ptr data,
2121 lt_ptr ignored)); 2171 lt_ptr ignored));
2122static int find_handle_callback LT_PARAMS((char *filename, lt_ptr data, 2172static int find_handle_callback LT_PARAMS ((char *filename, lt_ptr data,
2123 lt_ptr ignored)); 2173 lt_ptr ignored));
2124static int foreachfile_callback LT_PARAMS((char *filename, lt_ptr data1, 2174static int foreachfile_callback LT_PARAMS ((char *filename, lt_ptr data1,
2125 lt_ptr data2)); 2175 lt_ptr data2));
2126 2176
2127 2177
2128static int canonicalize_path LT_PARAMS((const char *path, 2178static int canonicalize_path LT_PARAMS ((const char *path,
2129 char **pcanonical)); 2179 char **pcanonical));
2130static int argzize_path LT_PARAMS((const char *path, 2180static int argzize_path LT_PARAMS ((const char *path,
2131 char **pargz, 2181 char **pargz, size_t * pargz_len));
2132 size_t *pargz_len)); 2182static FILE *find_file LT_PARAMS ((const char *search_path,
2133static FILE *find_file LT_PARAMS((const char *search_path, 2183 const char *base_name, char **pdir));
2134 const char *base_name, 2184static lt_dlhandle *find_handle LT_PARAMS ((const char *search_path,
2135 char **pdir)); 2185 const char *base_name,
2136static lt_dlhandle *find_handle LT_PARAMS((const char *search_path, 2186 lt_dlhandle * handle));
2137 const char *base_name, 2187static int find_module LT_PARAMS ((lt_dlhandle * handle,
2138 lt_dlhandle *handle)); 2188 const char *dir,
2139static int find_module LT_PARAMS((lt_dlhandle *handle, 2189 const char *libdir,
2140 const char *dir, 2190 const char *dlname,
2141 const char *libdir, 2191 const char *old_name, int installed));
2142 const char *dlname, 2192static int free_vars LT_PARAMS ((char *dlname, char *oldname,
2143 const char *old_name, 2193 char *libdir, char *deplibs));
2144 int installed)); 2194static int load_deplibs LT_PARAMS ((lt_dlhandle handle, char *deplibs));
2145static int free_vars LT_PARAMS((char *dlname, char *oldname, 2195static int trim LT_PARAMS ((char **dest, const char *str));
2146 char *libdir, char *deplibs)); 2196static int try_dlopen LT_PARAMS ((lt_dlhandle * handle,
2147static int load_deplibs LT_PARAMS((lt_dlhandle handle, 2197 const char *filename));
2148 char *deplibs)); 2198static int tryall_dlopen LT_PARAMS ((lt_dlhandle * handle,
2149static int trim LT_PARAMS((char **dest, 2199 const char *filename));
2150 const char *str)); 2200static int unload_deplibs LT_PARAMS ((lt_dlhandle handle));
2151static int try_dlopen LT_PARAMS((lt_dlhandle *handle, 2201static int lt_argz_insert LT_PARAMS ((char **pargz,
2152 const char *filename)); 2202 size_t * pargz_len,
2153static int tryall_dlopen LT_PARAMS((lt_dlhandle *handle, 2203 char *before, const char *entry));
2154 const char *filename)); 2204static int lt_argz_insertinorder LT_PARAMS ((char **pargz,
2155static int unload_deplibs LT_PARAMS((lt_dlhandle handle)); 2205 size_t * pargz_len,
2156static int lt_argz_insert LT_PARAMS((char **pargz, 2206 const char *entry));
2157 size_t *pargz_len, 2207static int lt_argz_insertdir LT_PARAMS ((char **pargz,
2158 char *before, 2208 size_t * pargz_len,
2159 const char *entry)); 2209 const char *dirnam,
2160static int lt_argz_insertinorder LT_PARAMS((char **pargz, 2210 struct dirent * dp));
2161 size_t *pargz_len, 2211static int lt_dlpath_insertdir LT_PARAMS ((char **ppath,
2162 const char *entry)); 2212 char *before, const char *dir));
2163static int lt_argz_insertdir LT_PARAMS((char **pargz, 2213static int list_files_by_dir LT_PARAMS ((const char *dirnam,
2164 size_t *pargz_len, 2214 char **pargz, size_t * pargz_len));
2165 const char *dirnam, 2215static int file_not_found LT_PARAMS ((void));
2166 struct dirent *dp)); 2216
2167static int lt_dlpath_insertdir LT_PARAMS((char **ppath, 2217static char *user_search_path = 0;
2168 char *before, 2218static lt_dlloader *loaders = 0;
2169 const char *dir)); 2219static lt_dlhandle handles = 0;
2170static int list_files_by_dir LT_PARAMS((const char *dirnam, 2220static int initialized = 0;
2171 char **pargz,
2172 size_t *pargz_len));
2173static int file_not_found LT_PARAMS((void));
2174
2175static char *user_search_path= 0;
2176static lt_dlloader *loaders = 0;
2177static lt_dlhandle handles = 0;
2178static int initialized = 0;
2179 2221
2180/* Initialize libltdl. */ 2222/* Initialize libltdl. */
2181int 2223int
2182lt_dlinit () 2224lt_dlinit ()
2183{ 2225{
2184 int errors = 0; 2226 int errors = 0;
2185 2227
2186 LT_DLMUTEX_LOCK (); 2228 LT_DLMUTEX_LOCK ();
2187 2229
@@ -2189,7 +2231,7 @@ lt_dlinit ()
2189 if (++initialized == 1) 2231 if (++initialized == 1)
2190 { 2232 {
2191 handles = 0; 2233 handles = 0;
2192 user_search_path = 0; /* empty search path */ 2234 user_search_path = 0; /* empty search path */
2193 2235
2194#if HAVE_LIBDL 2236#if HAVE_LIBDL
2195 errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dl, "dlopen"); 2237 errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dl, "dlopen");
@@ -2207,21 +2249,21 @@ lt_dlinit ()
2207 errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dld, "dld"); 2249 errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dld, "dld");
2208#endif 2250#endif
2209#if HAVE_DYLD 2251#if HAVE_DYLD
2210 errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dyld, "dyld"); 2252 errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dyld, "dyld");
2211 errors += sys_dyld_init(); 2253 errors += sys_dyld_init ();
2212#endif 2254#endif
2213 errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload"); 2255 errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload");
2214 2256
2215 if (presym_init (presym.dlloader_data)) 2257 if (presym_init (presym.dlloader_data))
2216 { 2258 {
2217 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER)); 2259 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER));
2218 ++errors; 2260 ++errors;
2219 } 2261 }
2220 else if (errors != 0) 2262 else if (errors != 0)
2221 { 2263 {
2222 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED)); 2264 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED));
2223 ++errors; 2265 ++errors;
2224 } 2266 }
2225 } 2267 }
2226 2268
2227 LT_DLMUTEX_UNLOCK (); 2269 LT_DLMUTEX_UNLOCK ();
@@ -2241,13 +2283,13 @@ lt_dlpreload (preloaded)
2241 } 2283 }
2242 else 2284 else
2243 { 2285 {
2244 presym_free_symlists(); 2286 presym_free_symlists ();
2245 2287
2246 LT_DLMUTEX_LOCK (); 2288 LT_DLMUTEX_LOCK ();
2247 if (default_preloaded_symbols) 2289 if (default_preloaded_symbols)
2248 { 2290 {
2249 errors = lt_dlpreload (default_preloaded_symbols); 2291 errors = lt_dlpreload (default_preloaded_symbols);
2250 } 2292 }
2251 LT_DLMUTEX_UNLOCK (); 2293 LT_DLMUTEX_UNLOCK ();
2252 } 2294 }
2253 2295
@@ -2269,7 +2311,7 @@ lt_dlexit ()
2269{ 2311{
2270 /* shut down libltdl */ 2312 /* shut down libltdl */
2271 lt_dlloader *loader; 2313 lt_dlloader *loader;
2272 int errors = 0; 2314 int errors = 0;
2273 2315
2274 LT_DLMUTEX_LOCK (); 2316 LT_DLMUTEX_LOCK ();
2275 loader = loaders; 2317 loader = loaders;
@@ -2284,54 +2326,54 @@ lt_dlexit ()
2284 /* shut down only at last call. */ 2326 /* shut down only at last call. */
2285 if (--initialized == 0) 2327 if (--initialized == 0)
2286 { 2328 {
2287 int level; 2329 int level;
2288 2330
2289 while (handles && LT_DLIS_RESIDENT (handles)) 2331 while (handles && LT_DLIS_RESIDENT (handles))
2290 { 2332 {
2291 handles = handles->next; 2333 handles = handles->next;
2292 } 2334 }
2293 2335
2294 /* close all modules */ 2336 /* close all modules */
2295 for (level = 1; handles; ++level) 2337 for (level = 1; handles; ++level)
2296 { 2338 {
2297 lt_dlhandle cur = handles; 2339 lt_dlhandle cur = handles;
2298 int saw_nonresident = 0; 2340 int saw_nonresident = 0;
2299 2341
2300 while (cur) 2342 while (cur)
2301 { 2343 {
2302 lt_dlhandle tmp = cur; 2344 lt_dlhandle tmp = cur;
2303 cur = cur->next; 2345 cur = cur->next;
2304 if (!LT_DLIS_RESIDENT (tmp)) 2346 if (!LT_DLIS_RESIDENT (tmp))
2305 saw_nonresident = 1; 2347 saw_nonresident = 1;
2306 if (!LT_DLIS_RESIDENT (tmp) && tmp->info.ref_count <= level) 2348 if (!LT_DLIS_RESIDENT (tmp) && tmp->info.ref_count <= level)
2307 { 2349 {
2308 if (lt_dlclose (tmp)) 2350 if (lt_dlclose (tmp))
2309 { 2351 {
2310 ++errors; 2352 ++errors;
2311 } 2353 }
2312 } 2354 }
2313 } 2355 }
2314 /* done if only resident modules are left */ 2356 /* done if only resident modules are left */
2315 if (!saw_nonresident) 2357 if (!saw_nonresident)
2316 break; 2358 break;
2317 } 2359 }
2318 2360
2319 /* close all loaders */ 2361 /* close all loaders */
2320 while (loader) 2362 while (loader)
2321 { 2363 {
2322 lt_dlloader *next = loader->next; 2364 lt_dlloader *next = loader->next;
2323 lt_user_data data = loader->dlloader_data; 2365 lt_user_data data = loader->dlloader_data;
2324 if (loader->dlloader_exit && loader->dlloader_exit (data)) 2366 if (loader->dlloader_exit && loader->dlloader_exit (data))
2325 { 2367 {
2326 ++errors; 2368 ++errors;
2327 } 2369 }
2328 2370
2329 LT_DLMEM_REASSIGN (loader, next); 2371 LT_DLMEM_REASSIGN (loader, next);
2330 } 2372 }
2331 loaders = 0; 2373 loaders = 0;
2332 } 2374 }
2333 2375
2334 done: 2376done:
2335 LT_DLMUTEX_UNLOCK (); 2377 LT_DLMUTEX_UNLOCK ();
2336 return errors; 2378 return errors;
2337} 2379}
@@ -2341,15 +2383,15 @@ tryall_dlopen (handle, filename)
2341 lt_dlhandle *handle; 2383 lt_dlhandle *handle;
2342 const char *filename; 2384 const char *filename;
2343{ 2385{
2344 lt_dlhandle cur; 2386 lt_dlhandle cur;
2345 lt_dlloader *loader; 2387 lt_dlloader *loader;
2346 const char *saved_error; 2388 const char *saved_error;
2347 int errors = 0; 2389 int errors = 0;
2348 2390
2349 LT_DLMUTEX_GETERROR (saved_error); 2391 LT_DLMUTEX_GETERROR (saved_error);
2350 LT_DLMUTEX_LOCK (); 2392 LT_DLMUTEX_LOCK ();
2351 2393
2352 cur = handles; 2394 cur = handles;
2353 loader = loaders; 2395 loader = loaders;
2354 2396
2355 /* check whether the module was already opened */ 2397 /* check whether the module was already opened */
@@ -2357,15 +2399,15 @@ tryall_dlopen (handle, filename)
2357 { 2399 {
2358 /* try to dlopen the program itself? */ 2400 /* try to dlopen the program itself? */
2359 if (!cur->info.filename && !filename) 2401 if (!cur->info.filename && !filename)
2360 { 2402 {
2361 break; 2403 break;
2362 } 2404 }
2363 2405
2364 if (cur->info.filename && filename 2406 if (cur->info.filename && filename
2365 && strcmp (cur->info.filename, filename) == 0) 2407 && strcmp (cur->info.filename, filename) == 0)
2366 { 2408 {
2367 break; 2409 break;
2368 } 2410 }
2369 2411
2370 cur = cur->next; 2412 cur = cur->next;
2371 } 2413 }
@@ -2381,23 +2423,23 @@ tryall_dlopen (handle, filename)
2381 if (filename) 2423 if (filename)
2382 { 2424 {
2383 /* Comment out the check of file permissions using access. 2425 /* Comment out the check of file permissions using access.
2384 This call seems to always return -1 with error EACCES. 2426 This call seems to always return -1 with error EACCES.
2385 */ 2427 */
2386 /* We need to catch missing file errors early so that 2428 /* We need to catch missing file errors early so that
2387 file_not_found() can detect what happened. 2429 file_not_found() can detect what happened.
2388 if (access (filename, R_OK) != 0) 2430 if (access (filename, R_OK) != 0)
2389 { 2431 {
2390 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); 2432 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
2391 ++errors; 2433 ++errors;
2392 goto done; 2434 goto done;
2393 } */ 2435 } */
2394 2436
2395 cur->info.filename = lt_estrdup (filename); 2437 cur->info.filename = lt_estrdup (filename);
2396 if (!cur->info.filename) 2438 if (!cur->info.filename)
2397 { 2439 {
2398 ++errors; 2440 ++errors;
2399 goto done; 2441 goto done;
2400 } 2442 }
2401 } 2443 }
2402 else 2444 else
2403 { 2445 {
@@ -2411,9 +2453,9 @@ tryall_dlopen (handle, filename)
2411 cur->module = loader->module_open (data, filename); 2453 cur->module = loader->module_open (data, filename);
2412 2454
2413 if (cur->module != 0) 2455 if (cur->module != 0)
2414 { 2456 {
2415 break; 2457 break;
2416 } 2458 }
2417 loader = loader->next; 2459 loader = loader->next;
2418 } 2460 }
2419 2461
@@ -2424,10 +2466,10 @@ tryall_dlopen (handle, filename)
2424 goto done; 2466 goto done;
2425 } 2467 }
2426 2468
2427 cur->loader = loader; 2469 cur->loader = loader;
2428 LT_DLMUTEX_SETERROR (saved_error); 2470 LT_DLMUTEX_SETERROR (saved_error);
2429 2471
2430 done: 2472done:
2431 LT_DLMUTEX_UNLOCK (); 2473 LT_DLMUTEX_UNLOCK ();
2432 2474
2433 return errors; 2475 return errors;
@@ -2440,10 +2482,10 @@ tryall_dlopen_module (handle, prefix, dirname, dlname)
2440 const char *dirname; 2482 const char *dirname;
2441 const char *dlname; 2483 const char *dlname;
2442{ 2484{
2443 int error = 0; 2485 int error = 0;
2444 char *filename = 0; 2486 char *filename = 0;
2445 size_t filename_len = 0; 2487 size_t filename_len = 0;
2446 size_t dirname_len = LT_STRLEN (dirname); 2488 size_t dirname_len = LT_STRLEN (dirname);
2447 2489
2448 assert (handle); 2490 assert (handle);
2449 assert (dirname); 2491 assert (dirname);
@@ -2455,13 +2497,13 @@ tryall_dlopen_module (handle, prefix, dirname, dlname)
2455#endif 2497#endif
2456 2498
2457 if (dirname_len > 0) 2499 if (dirname_len > 0)
2458 if (dirname[dirname_len -1] == '/') 2500 if (dirname[dirname_len - 1] == '/')
2459 --dirname_len; 2501 --dirname_len;
2460 filename_len = dirname_len + 1 + LT_STRLEN (dlname); 2502 filename_len = dirname_len + 1 + LT_STRLEN (dlname);
2461 2503
2462 /* Allocate memory, and combine DIRNAME and MODULENAME into it. 2504 /* Allocate memory, and combine DIRNAME and MODULENAME into it.
2463 The PREFIX (if any) is handled below. */ 2505 The PREFIX (if any) is handled below. */
2464 filename = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1); 2506 filename = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1);
2465 if (!filename) 2507 if (!filename)
2466 return 1; 2508 return 1;
2467 2509
@@ -2473,7 +2515,7 @@ tryall_dlopen_module (handle, prefix, dirname, dlname)
2473 if (prefix) 2515 if (prefix)
2474 { 2516 {
2475 error += tryall_dlopen_module (handle, 2517 error += tryall_dlopen_module (handle,
2476 (const char *) 0, prefix, filename); 2518 (const char *) 0, prefix, filename);
2477 } 2519 }
2478 else if (tryall_dlopen (handle, filename) != 0) 2520 else if (tryall_dlopen (handle, filename) != 0)
2479 { 2521 {
@@ -2506,24 +2548,23 @@ find_module (handle, dir, libdir, dlname, old_name, installed)
2506 { 2548 {
2507 /* try to open the installed module */ 2549 /* try to open the installed module */
2508 if (installed && libdir) 2550 if (installed && libdir)
2509 { 2551 {
2510 if (tryall_dlopen_module (handle, 2552 if (tryall_dlopen_module (handle,
2511 (const char *) 0, libdir, dlname) == 0) 2553 (const char *) 0, libdir, dlname) == 0)
2512 return 0; 2554 return 0;
2513 } 2555 }
2514 2556
2515 /* try to open the not-installed module */ 2557 /* try to open the not-installed module */
2516 if (!installed) 2558 if (!installed)
2517 { 2559 {
2518 if (tryall_dlopen_module (handle, dir, objdir, dlname) == 0) 2560 if (tryall_dlopen_module (handle, dir, objdir, dlname) == 0)
2519 return 0; 2561 return 0;
2520 } 2562 }
2521 2563
2522 /* maybe it was moved to another directory */ 2564 /* maybe it was moved to another directory */
2523 { 2565 {
2524 if (tryall_dlopen_module (handle, 2566 if (tryall_dlopen_module (handle, (const char *) 0, dir, dlname) == 0)
2525 (const char *) 0, dir, dlname) == 0) 2567 return 0;
2526 return 0;
2527 } 2568 }
2528 } 2569 }
2529 2570
@@ -2541,7 +2582,7 @@ canonicalize_path (path, pcanonical)
2541 assert (path && *path); 2582 assert (path && *path);
2542 assert (pcanonical); 2583 assert (pcanonical);
2543 2584
2544 canonical = LT_EMALLOC (char, 1+ LT_STRLEN (path)); 2585 canonical = LT_EMALLOC (char, 1 + LT_STRLEN (path));
2545 if (!canonical) 2586 if (!canonical)
2546 return 1; 2587 return 1;
2547 2588
@@ -2550,38 +2591,38 @@ canonicalize_path (path, pcanonical)
2550 size_t src; 2591 size_t src;
2551 for (src = 0; path[src] != LT_EOS_CHAR; ++src) 2592 for (src = 0; path[src] != LT_EOS_CHAR; ++src)
2552 { 2593 {
2553 /* Path separators are not copied to the beginning or end of 2594 /* Path separators are not copied to the beginning or end of
2554 the destination, or if another separator would follow 2595 the destination, or if another separator would follow
2555 immediately. */ 2596 immediately. */
2556 if (path[src] == LT_PATHSEP_CHAR) 2597 if (path[src] == LT_PATHSEP_CHAR)
2557 { 2598 {
2558 if ((dest == 0) 2599 if ((dest == 0)
2559 || (path[1+ src] == LT_PATHSEP_CHAR) 2600 || (path[1 + src] == LT_PATHSEP_CHAR)
2560 || (path[1+ src] == LT_EOS_CHAR)) 2601 || (path[1 + src] == LT_EOS_CHAR))
2561 continue; 2602 continue;
2562 } 2603 }
2563 2604
2564 /* Anything other than a directory separator is copied verbatim. */ 2605 /* Anything other than a directory separator is copied verbatim. */
2565 if ((path[src] != '/') 2606 if ((path[src] != '/')
2566#ifdef LT_DIRSEP_CHAR 2607#ifdef LT_DIRSEP_CHAR
2567 && (path[src] != LT_DIRSEP_CHAR) 2608 && (path[src] != LT_DIRSEP_CHAR)
2568#endif 2609#endif
2569 ) 2610 )
2570 { 2611 {
2571 canonical[dest++] = path[src]; 2612 canonical[dest++] = path[src];
2572 } 2613 }
2573 /* Directory separators are converted and copied only if they are 2614 /* Directory separators are converted and copied only if they are
2574 not at the end of a path -- i.e. before a path separator or 2615 not at the end of a path -- i.e. before a path separator or
2575 NULL terminator. */ 2616 NULL terminator. */
2576 else if ((path[1+ src] != LT_PATHSEP_CHAR) 2617 else if ((path[1 + src] != LT_PATHSEP_CHAR)
2577 && (path[1+ src] != LT_EOS_CHAR) 2618 && (path[1 + src] != LT_EOS_CHAR)
2578#ifdef LT_DIRSEP_CHAR 2619#ifdef LT_DIRSEP_CHAR
2579 && (path[1+ src] != LT_DIRSEP_CHAR) 2620 && (path[1 + src] != LT_DIRSEP_CHAR)
2580#endif 2621#endif
2581 && (path[1+ src] != '/')) 2622 && (path[1 + src] != '/'))
2582 { 2623 {
2583 canonical[dest++] = '/'; 2624 canonical[dest++] = '/';
2584 } 2625 }
2585 } 2626 }
2586 2627
2587 /* Add an end-of-string marker at the end. */ 2628 /* Add an end-of-string marker at the end. */
@@ -2609,14 +2650,14 @@ argzize_path (path, pargz, pargz_len)
2609 if ((error = argz_create_sep (path, LT_PATHSEP_CHAR, pargz, pargz_len))) 2650 if ((error = argz_create_sep (path, LT_PATHSEP_CHAR, pargz, pargz_len)))
2610 { 2651 {
2611 switch (error) 2652 switch (error)
2612 { 2653 {
2613 case ENOMEM: 2654 case ENOMEM:
2614 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); 2655 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2615 break; 2656 break;
2616 default: 2657 default:
2617 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); 2658 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN));
2618 break; 2659 break;
2619 } 2660 }
2620 2661
2621 return 1; 2662 return 1;
2622 } 2663 }
@@ -2636,13 +2677,13 @@ foreach_dirinpath (search_path, base_name, func, data1, data2)
2636 lt_ptr data1; 2677 lt_ptr data1;
2637 lt_ptr data2; 2678 lt_ptr data2;
2638{ 2679{
2639 int result = 0; 2680 int result = 0;
2640 int filenamesize = 0; 2681 int filenamesize = 0;
2641 size_t lenbase = LT_STRLEN (base_name); 2682 size_t lenbase = LT_STRLEN (base_name);
2642 size_t argz_len = 0; 2683 size_t argz_len = 0;
2643 char *argz = 0; 2684 char *argz = 0;
2644 char *filename = 0; 2685 char *filename = 0;
2645 char *canonical = 0; 2686 char *canonical = 0;
2646 2687
2647 LT_DLMUTEX_LOCK (); 2688 LT_DLMUTEX_LOCK ();
2648 2689
@@ -2662,35 +2703,35 @@ foreach_dirinpath (search_path, base_name, func, data1, data2)
2662 char *dir_name = 0; 2703 char *dir_name = 0;
2663 while ((dir_name = argz_next (argz, argz_len, dir_name))) 2704 while ((dir_name = argz_next (argz, argz_len, dir_name)))
2664 { 2705 {
2665 size_t lendir = LT_STRLEN (dir_name); 2706 size_t lendir = LT_STRLEN (dir_name);
2666 2707
2667 if (lendir +1 +lenbase >= filenamesize) 2708 if (lendir + 1 + lenbase >= filenamesize)
2668 { 2709 {
2669 LT_DLFREE (filename); 2710 LT_DLFREE (filename);
2670 filenamesize = lendir +1 +lenbase +1; /* "/d" + '/' + "f" + '\0' */ 2711 filenamesize = lendir + 1 + lenbase + 1; /* "/d" + '/' + "f" + '\0' */
2671 filename = LT_EMALLOC (char, filenamesize); 2712 filename = LT_EMALLOC (char, filenamesize);
2672 if (!filename) 2713 if (!filename)
2673 goto cleanup; 2714 goto cleanup;
2674 } 2715 }
2675 2716
2676 assert (filenamesize > lendir); 2717 assert (filenamesize > lendir);
2677 strcpy (filename, dir_name); 2718 strcpy (filename, dir_name);
2678 2719
2679 if (base_name && *base_name) 2720 if (base_name && *base_name)
2680 { 2721 {
2681 if (filename[lendir -1] != '/') 2722 if (filename[lendir - 1] != '/')
2682 filename[lendir++] = '/'; 2723 filename[lendir++] = '/';
2683 strcpy (filename +lendir, base_name); 2724 strcpy (filename + lendir, base_name);
2684 } 2725 }
2685 2726
2686 if ((result = (*func) (filename, data1, data2))) 2727 if ((result = (*func) (filename, data1, data2)))
2687 { 2728 {
2688 break; 2729 break;
2689 } 2730 }
2690 } 2731 }
2691 } 2732 }
2692 2733
2693 cleanup: 2734cleanup:
2694 LT_DLFREE (argz); 2735 LT_DLFREE (argz);
2695 LT_DLFREE (canonical); 2736 LT_DLFREE (canonical);
2696 LT_DLFREE (filename); 2737 LT_DLFREE (filename);
@@ -2709,9 +2750,9 @@ find_file_callback (filename, data1, data2)
2709 lt_ptr data1; 2750 lt_ptr data1;
2710 lt_ptr data2; 2751 lt_ptr data2;
2711{ 2752{
2712 char **pdir = (char **) data1; 2753 char **pdir = (char **) data1;
2713 FILE **pfile = (FILE **) data2; 2754 FILE **pfile = (FILE **) data2;
2714 int is_done = 0; 2755 int is_done = 0;
2715 2756
2716 assert (filename && *filename); 2757 assert (filename && *filename);
2717 assert (pdir); 2758 assert (pdir);
@@ -2722,10 +2763,10 @@ find_file_callback (filename, data1, data2)
2722 char *dirend = strrchr (filename, '/'); 2763 char *dirend = strrchr (filename, '/');
2723 2764
2724 if (dirend > filename) 2765 if (dirend > filename)
2725 *dirend = LT_EOS_CHAR; 2766 *dirend = LT_EOS_CHAR;
2726 2767
2727 LT_DLFREE (*pdir); 2768 LT_DLFREE (*pdir);
2728 *pdir = lt_estrdup (filename); 2769 *pdir = lt_estrdup (filename);
2729 is_done = (*pdir == 0) ? -1 : 1; 2770 is_done = (*pdir == 0) ? -1 : 1;
2730 } 2771 }
2731 2772
@@ -2751,8 +2792,8 @@ find_handle_callback (filename, data, ignored)
2751 lt_ptr data; 2792 lt_ptr data;
2752 lt_ptr ignored; 2793 lt_ptr ignored;
2753{ 2794{
2754 lt_dlhandle *handle = (lt_dlhandle *) data; 2795 lt_dlhandle *handle = (lt_dlhandle *) data;
2755 int notfound = access (filename, R_OK); 2796 int notfound = access (filename, R_OK);
2756 2797
2757 /* Bail out if file cannot be read... */ 2798 /* Bail out if file cannot be read... */
2758 if (notfound) 2799 if (notfound)
@@ -2778,7 +2819,7 @@ find_handle (search_path, base_name, handle)
2778 return 0; 2819 return 0;
2779 2820
2780 if (!foreach_dirinpath (search_path, base_name, find_handle_callback, 2821 if (!foreach_dirinpath (search_path, base_name, find_handle_callback,
2781 handle, 0)) 2822 handle, 0))
2782 return 0; 2823 return 0;
2783 2824
2784 return handle; 2825 return handle;
@@ -2790,12 +2831,12 @@ load_deplibs (handle, deplibs)
2790 char *deplibs; 2831 char *deplibs;
2791{ 2832{
2792#if LTDL_DLOPEN_DEPLIBS 2833#if LTDL_DLOPEN_DEPLIBS
2793 char *p, *save_search_path = 0; 2834 char *p, *save_search_path = 0;
2794 int depcount = 0; 2835 int depcount = 0;
2795 int i; 2836 int i;
2796 char **names = 0; 2837 char **names = 0;
2797#endif 2838#endif
2798 int errors = 0; 2839 int errors = 0;
2799 2840
2800 handle->depcount = 0; 2841 handle->depcount = 0;
2801 2842
@@ -2811,7 +2852,7 @@ load_deplibs (handle, deplibs)
2811 { 2852 {
2812 save_search_path = lt_estrdup (user_search_path); 2853 save_search_path = lt_estrdup (user_search_path);
2813 if (!save_search_path) 2854 if (!save_search_path)
2814 goto cleanup; 2855 goto cleanup;
2815 } 2856 }
2816 2857
2817 /* extract search paths and count deplibs */ 2858 /* extract search paths and count deplibs */
@@ -2819,34 +2860,34 @@ load_deplibs (handle, deplibs)
2819 while (*p) 2860 while (*p)
2820 { 2861 {
2821 if (!isspace ((int) *p)) 2862 if (!isspace ((int) *p))
2822 { 2863 {
2823 char *end = p+1; 2864 char *end = p + 1;
2824 while (*end && !isspace((int) *end)) 2865 while (*end && !isspace ((int) *end))
2825 { 2866 {
2826 ++end; 2867 ++end;
2827 } 2868 }
2828 2869
2829 if (strncmp(p, "-L", 2) == 0 || strncmp(p, "-R", 2) == 0) 2870 if (strncmp (p, "-L", 2) == 0 || strncmp (p, "-R", 2) == 0)
2830 { 2871 {
2831 char save = *end; 2872 char save = *end;
2832 *end = 0; /* set a temporary string terminator */ 2873 *end = 0; /* set a temporary string terminator */
2833 if (lt_dladdsearchdir(p+2)) 2874 if (lt_dladdsearchdir (p + 2))
2834 { 2875 {
2835 goto cleanup; 2876 goto cleanup;
2836 } 2877 }
2837 *end = save; 2878 *end = save;
2838 } 2879 }
2839 else 2880 else
2840 { 2881 {
2841 ++depcount; 2882 ++depcount;
2842 } 2883 }
2843 2884
2844 p = end; 2885 p = end;
2845 } 2886 }
2846 else 2887 else
2847 { 2888 {
2848 ++p; 2889 ++p;
2849 } 2890 }
2850 } 2891 }
2851 2892
2852 /* restore the old search path */ 2893 /* restore the old search path */
@@ -2861,7 +2902,7 @@ load_deplibs (handle, deplibs)
2861 goto cleanup; 2902 goto cleanup;
2862 } 2903 }
2863 2904
2864 names = LT_EMALLOC (char *, depcount * sizeof (char*)); 2905 names = LT_EMALLOC (char *, depcount * sizeof (char *));
2865 if (!names) 2906 if (!names)
2866 goto cleanup; 2907 goto cleanup;
2867 2908
@@ -2871,40 +2912,40 @@ load_deplibs (handle, deplibs)
2871 while (*p) 2912 while (*p)
2872 { 2913 {
2873 if (isspace ((int) *p)) 2914 if (isspace ((int) *p))
2874 { 2915 {
2875 ++p; 2916 ++p;
2876 } 2917 }
2877 else 2918 else
2878 { 2919 {
2879 char *end = p+1; 2920 char *end = p + 1;
2880 while (*end && !isspace ((int) *end)) 2921 while (*end && !isspace ((int) *end))
2881 { 2922 {
2882 ++end; 2923 ++end;
2883 } 2924 }
2884 2925
2885 if (strncmp(p, "-L", 2) != 0 && strncmp(p, "-R", 2) != 0) 2926 if (strncmp (p, "-L", 2) != 0 && strncmp (p, "-R", 2) != 0)
2886 { 2927 {
2887 char *name; 2928 char *name;
2888 char save = *end; 2929 char save = *end;
2889 *end = 0; /* set a temporary string terminator */ 2930 *end = 0; /* set a temporary string terminator */
2890 if (strncmp(p, "-l", 2) == 0) 2931 if (strncmp (p, "-l", 2) == 0)
2891 { 2932 {
2892 size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2); 2933 size_t name_len = 3 + /* "lib" */ LT_STRLEN (p + 2);
2893 name = LT_EMALLOC (char, 1+ name_len); 2934 name = LT_EMALLOC (char, 1 + name_len);
2894 if (name) 2935 if (name)
2895 sprintf (name, "lib%s", p+2); 2936 sprintf (name, "lib%s", p + 2);
2896 } 2937 }
2897 else 2938 else
2898 name = lt_estrdup(p); 2939 name = lt_estrdup (p);
2899 2940
2900 if (!name) 2941 if (!name)
2901 goto cleanup_names; 2942 goto cleanup_names;
2902 2943
2903 names[depcount++] = name; 2944 names[depcount++] = name;
2904 *end = save; 2945 *end = save;
2905 } 2946 }
2906 p = end; 2947 p = end;
2907 } 2948 }
2908 } 2949 }
2909 2950
2910 /* load the deplibs (in reverse order) 2951 /* load the deplibs (in reverse order)
@@ -2914,32 +2955,32 @@ load_deplibs (handle, deplibs)
2914 later on if the loaded module cannot resolve all of its symbols. */ 2955 later on if the loaded module cannot resolve all of its symbols. */
2915 if (depcount) 2956 if (depcount)
2916 { 2957 {
2917 int j = 0; 2958 int j = 0;
2918 2959
2919 handle->deplibs = (lt_dlhandle*) LT_EMALLOC (lt_dlhandle *, depcount); 2960 handle->deplibs = (lt_dlhandle *) LT_EMALLOC (lt_dlhandle *, depcount);
2920 if (!handle->deplibs) 2961 if (!handle->deplibs)
2921 goto cleanup; 2962 goto cleanup;
2922 2963
2923 for (i = 0; i < depcount; ++i) 2964 for (i = 0; i < depcount; ++i)
2924 { 2965 {
2925 handle->deplibs[j] = lt_dlopenext(names[depcount-1-i]); 2966 handle->deplibs[j] = lt_dlopenext (names[depcount - 1 - i]);
2926 if (handle->deplibs[j]) 2967 if (handle->deplibs[j])
2927 { 2968 {
2928 ++j; 2969 ++j;
2929 } 2970 }
2930 } 2971 }
2931 2972
2932 handle->depcount = j; /* Number of successfully loaded deplibs */ 2973 handle->depcount = j; /* Number of successfully loaded deplibs */
2933 errors = 0; 2974 errors = 0;
2934 } 2975 }
2935 2976
2936 cleanup_names: 2977cleanup_names:
2937 for (i = 0; i < depcount; ++i) 2978 for (i = 0; i < depcount; ++i)
2938 { 2979 {
2939 LT_DLFREE (names[i]); 2980 LT_DLFREE (names[i]);
2940 } 2981 }
2941 2982
2942 cleanup: 2983cleanup:
2943 LT_DLFREE (names); 2984 LT_DLFREE (names);
2944#endif 2985#endif
2945 2986
@@ -2956,12 +2997,12 @@ unload_deplibs (handle)
2956 if (handle->depcount) 2997 if (handle->depcount)
2957 { 2998 {
2958 for (i = 0; i < handle->depcount; ++i) 2999 for (i = 0; i < handle->depcount; ++i)
2959 { 3000 {
2960 if (!LT_DLIS_RESIDENT (handle->deplibs[i])) 3001 if (!LT_DLIS_RESIDENT (handle->deplibs[i]))
2961 { 3002 {
2962 errors += lt_dlclose (handle->deplibs[i]); 3003 errors += lt_dlclose (handle->deplibs[i]);
2963 } 3004 }
2964 } 3005 }
2965 } 3006 }
2966 3007
2967 return errors; 3008 return errors;
@@ -2974,8 +3015,8 @@ trim (dest, str)
2974{ 3015{
2975 /* remove the leading and trailing "'" from str 3016 /* remove the leading and trailing "'" from str
2976 and store the result in dest */ 3017 and store the result in dest */
2977 const char *end = strrchr (str, '\''); 3018 const char *end = strrchr (str, '\'');
2978 size_t len = LT_STRLEN (str); 3019 size_t len = LT_STRLEN (str);
2979 char *tmp; 3020 char *tmp;
2980 3021
2981 LT_DLFREE (*dest); 3022 LT_DLFREE (*dest);
@@ -2984,10 +3025,10 @@ trim (dest, str)
2984 { 3025 {
2985 tmp = LT_EMALLOC (char, end - str); 3026 tmp = LT_EMALLOC (char, end - str);
2986 if (!tmp) 3027 if (!tmp)
2987 return 1; 3028 return 1;
2988 3029
2989 strncpy(tmp, &str[1], (end - str) - 1); 3030 strncpy (tmp, &str[1], (end - str) - 1);
2990 tmp[len-3] = LT_EOS_CHAR; 3031 tmp[len - 3] = LT_EOS_CHAR;
2991 *dest = tmp; 3032 *dest = tmp;
2992 } 3033 }
2993 else 3034 else
@@ -3018,14 +3059,14 @@ try_dlopen (phandle, filename)
3018 lt_dlhandle *phandle; 3059 lt_dlhandle *phandle;
3019 const char *filename; 3060 const char *filename;
3020{ 3061{
3021 const char * ext = 0; 3062 const char *ext = 0;
3022 const char * saved_error = 0; 3063 const char *saved_error = 0;
3023 char * canonical = 0; 3064 char *canonical = 0;
3024 char * base_name = 0; 3065 char *base_name = 0;
3025 char * dir = 0; 3066 char *dir = 0;
3026 char * name = 0; 3067 char *name = 0;
3027 int errors = 0; 3068 int errors = 0;
3028 lt_dlhandle newhandle; 3069 lt_dlhandle newhandle;
3029 3070
3030 assert (phandle); 3071 assert (phandle);
3031 assert (*phandle == 0); 3072 assert (*phandle == 0);
@@ -3037,19 +3078,19 @@ try_dlopen (phandle, filename)
3037 { 3078 {
3038 *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); 3079 *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
3039 if (*phandle == 0) 3080 if (*phandle == 0)
3040 return 1; 3081 return 1;
3041 3082
3042 memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); 3083 memset (*phandle, 0, sizeof (struct lt_dlhandle_struct));
3043 newhandle = *phandle; 3084 newhandle = *phandle;
3044 3085
3045 /* lt_dlclose()ing yourself is very bad! Disallow it. */ 3086 /* lt_dlclose()ing yourself is very bad! Disallow it. */
3046 LT_DLSET_FLAG (*phandle, LT_DLRESIDENT_FLAG); 3087 LT_DLSET_FLAG (*phandle, LT_DLRESIDENT_FLAG);
3047 3088
3048 if (tryall_dlopen (&newhandle, 0) != 0) 3089 if (tryall_dlopen (&newhandle, 0) != 0)
3049 { 3090 {
3050 LT_DLFREE (*phandle); 3091 LT_DLFREE (*phandle);
3051 return 1; 3092 return 1;
3052 } 3093 }
3053 3094
3054 goto register_handle; 3095 goto register_handle;
3055 } 3096 }
@@ -3069,14 +3110,14 @@ try_dlopen (phandle, filename)
3069 base_name = strrchr (canonical, '/'); 3110 base_name = strrchr (canonical, '/');
3070 if (base_name) 3111 if (base_name)
3071 { 3112 {
3072 size_t dirlen = (1+ base_name) - canonical; 3113 size_t dirlen = (1 + base_name) - canonical;
3073 3114
3074 dir = LT_EMALLOC (char, 1+ dirlen); 3115 dir = LT_EMALLOC (char, 1 + dirlen);
3075 if (!dir) 3116 if (!dir)
3076 { 3117 {
3077 ++errors; 3118 ++errors;
3078 goto cleanup; 3119 goto cleanup;
3079 } 3120 }
3080 3121
3081 strncpy (dir, canonical, dirlen); 3122 strncpy (dir, canonical, dirlen);
3082 dir[dirlen] = LT_EOS_CHAR; 3123 dir[dirlen] = LT_EOS_CHAR;
@@ -3093,41 +3134,41 @@ try_dlopen (phandle, filename)
3093 if (ext && strcmp (ext, archive_ext) == 0) 3134 if (ext && strcmp (ext, archive_ext) == 0)
3094 { 3135 {
3095 /* this seems to be a libtool module */ 3136 /* this seems to be a libtool module */
3096 FILE * file = 0; 3137 FILE *file = 0;
3097 char * dlname = 0; 3138 char *dlname = 0;
3098 char * old_name = 0; 3139 char *old_name = 0;
3099 char * libdir = 0; 3140 char *libdir = 0;
3100 char * deplibs = 0; 3141 char *deplibs = 0;
3101 char * line = 0; 3142 char *line = 0;
3102 size_t line_len; 3143 size_t line_len;
3103 3144
3104 /* if we can't find the installed flag, it is probably an 3145 /* if we can't find the installed flag, it is probably an
3105 installed libtool archive, produced with an old version 3146 installed libtool archive, produced with an old version
3106 of libtool */ 3147 of libtool */
3107 int installed = 1; 3148 int installed = 1;
3108 3149
3109 /* extract the module name from the file name */ 3150 /* extract the module name from the file name */
3110 name = LT_EMALLOC (char, ext - base_name + 1); 3151 name = LT_EMALLOC (char, ext - base_name + 1);
3111 if (!name) 3152 if (!name)
3112 { 3153 {
3113 ++errors; 3154 ++errors;
3114 goto cleanup; 3155 goto cleanup;
3115 } 3156 }
3116 3157
3117 /* canonicalize the module name */ 3158 /* canonicalize the module name */
3118 { 3159 {
3119 size_t i; 3160 size_t i;
3120 for (i = 0; i < ext - base_name; ++i) 3161 for (i = 0; i < ext - base_name; ++i)
3121 { 3162 {
3122 if (isalnum ((int)(base_name[i]))) 3163 if (isalnum ((int) (base_name[i])))
3123 { 3164 {
3124 name[i] = base_name[i]; 3165 name[i] = base_name[i];
3125 } 3166 }
3126 else 3167 else
3127 { 3168 {
3128 name[i] = '_'; 3169 name[i] = '_';
3129 } 3170 }
3130 } 3171 }
3131 name[ext - base_name] = LT_EOS_CHAR; 3172 name[ext - base_name] = LT_EOS_CHAR;
3132 } 3173 }
3133 3174
@@ -3136,146 +3177,145 @@ try_dlopen (phandle, filename)
3136 prescribed paths. Otherwise (or in any case if the module was not 3177 prescribed paths. Otherwise (or in any case if the module was not
3137 yet found) try opening just the module name as passed. */ 3178 yet found) try opening just the module name as passed. */
3138 if (!dir) 3179 if (!dir)
3139 { 3180 {
3140 const char *search_path; 3181 const char *search_path;
3141 3182
3142 LT_DLMUTEX_LOCK (); 3183 LT_DLMUTEX_LOCK ();
3143 search_path = user_search_path; 3184 search_path = user_search_path;
3144 if (search_path) 3185 if (search_path)
3145 file = find_file (user_search_path, base_name, &dir); 3186 file = find_file (user_search_path, base_name, &dir);
3146 LT_DLMUTEX_UNLOCK (); 3187 LT_DLMUTEX_UNLOCK ();
3147 3188
3148 if (!file) 3189 if (!file)
3149 { 3190 {
3150 search_path = getenv (LTDL_SEARCHPATH_VAR); 3191 search_path = getenv (LTDL_SEARCHPATH_VAR);
3151 if (search_path) 3192 if (search_path)
3152 file = find_file (search_path, base_name, &dir); 3193 file = find_file (search_path, base_name, &dir);
3153 } 3194 }
3154 3195
3155#ifdef LTDL_SHLIBPATH_VAR 3196#ifdef LTDL_SHLIBPATH_VAR
3156 if (!file) 3197 if (!file)
3157 { 3198 {
3158 search_path = getenv (LTDL_SHLIBPATH_VAR); 3199 search_path = getenv (LTDL_SHLIBPATH_VAR);
3159 if (search_path) 3200 if (search_path)
3160 file = find_file (search_path, base_name, &dir); 3201 file = find_file (search_path, base_name, &dir);
3161 } 3202 }
3162#endif 3203#endif
3163#ifdef LTDL_SYSSEARCHPATH 3204#ifdef LTDL_SYSSEARCHPATH
3164 if (!file && sys_search_path) 3205 if (!file && sys_search_path)
3165 { 3206 {
3166 file = find_file (sys_search_path, base_name, &dir); 3207 file = find_file (sys_search_path, base_name, &dir);
3167 } 3208 }
3168#endif 3209#endif
3169 } 3210 }
3170 if (!file) 3211 if (!file)
3171 { 3212 {
3172 file = fopen (filename, LT_READTEXT_MODE); 3213 file = fopen (filename, LT_READTEXT_MODE);
3173 } 3214 }
3174 3215
3175 /* If we didn't find the file by now, it really isn't there. Set 3216 /* If we didn't find the file by now, it really isn't there. Set
3176 the status flag, and bail out. */ 3217 the status flag, and bail out. */
3177 if (!file) 3218 if (!file)
3178 { 3219 {
3179 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); 3220 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
3180 ++errors; 3221 ++errors;
3181 goto cleanup; 3222 goto cleanup;
3182 } 3223 }
3183 3224
3184 line_len = LT_FILENAME_MAX; 3225 line_len = LT_FILENAME_MAX;
3185 line = LT_EMALLOC (char, line_len); 3226 line = LT_EMALLOC (char, line_len);
3186 if (!line) 3227 if (!line)
3187 { 3228 {
3188 fclose (file); 3229 fclose (file);
3189 ++errors; 3230 ++errors;
3190 goto cleanup; 3231 goto cleanup;
3191 } 3232 }
3192 3233
3193 /* read the .la file */ 3234 /* read the .la file */
3194 while (!feof (file)) 3235 while (!feof (file))
3195 { 3236 {
3196 if (!fgets (line, (int) line_len, file)) 3237 if (!fgets (line, (int) line_len, file))
3197 { 3238 {
3198 break; 3239 break;
3199 } 3240 }
3200 3241
3201 /* Handle the case where we occasionally need to read a line 3242 /* Handle the case where we occasionally need to read a line
3202 that is longer than the initial buffer size. */ 3243 that is longer than the initial buffer size. */
3203 while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file))) 3244 while ((line[LT_STRLEN (line) - 1] != '\n') && (!feof (file)))
3204 { 3245 {
3205 line = LT_DLREALLOC (char, line, line_len *2); 3246 line = LT_DLREALLOC (char, line, line_len * 2);
3206 if (!fgets (&line[line_len -1], (int) line_len +1, file)) 3247 if (!fgets (&line[line_len - 1], (int) line_len + 1, file))
3207 { 3248 {
3208 break; 3249 break;
3209 } 3250 }
3210 line_len *= 2; 3251 line_len *= 2;
3211 } 3252 }
3212 3253
3213 if (line[0] == '\n' || line[0] == '#') 3254 if (line[0] == '\n' || line[0] == '#')
3214 { 3255 {
3215 continue; 3256 continue;
3216 } 3257 }
3217 3258
3218#undef STR_DLNAME 3259#undef STR_DLNAME
3219#define STR_DLNAME "dlname=" 3260#define STR_DLNAME "dlname="
3220 if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) 3261 if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0)
3221 { 3262 {
3222 errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]); 3263 errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]);
3223 } 3264 }
3224 3265
3225#undef STR_OLD_LIBRARY 3266#undef STR_OLD_LIBRARY
3226#define STR_OLD_LIBRARY "old_library=" 3267#define STR_OLD_LIBRARY "old_library="
3227 else if (strncmp (line, STR_OLD_LIBRARY, 3268 else if (strncmp (line, STR_OLD_LIBRARY,
3228 sizeof (STR_OLD_LIBRARY) - 1) == 0) 3269 sizeof (STR_OLD_LIBRARY) - 1) == 0)
3229 { 3270 {
3230 errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); 3271 errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]);
3231 } 3272 }
3232#undef STR_LIBDIR 3273#undef STR_LIBDIR
3233#define STR_LIBDIR "libdir=" 3274#define STR_LIBDIR "libdir="
3234 else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) 3275 else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0)
3235 { 3276 {
3236 errors += trim (&libdir, &line[sizeof(STR_LIBDIR) - 1]); 3277 errors += trim (&libdir, &line[sizeof (STR_LIBDIR) - 1]);
3237 } 3278 }
3238 3279
3239#undef STR_DL_DEPLIBS 3280#undef STR_DL_DEPLIBS
3240#define STR_DL_DEPLIBS "dependency_libs=" 3281#define STR_DL_DEPLIBS "dependency_libs="
3241 else if (strncmp (line, STR_DL_DEPLIBS, 3282 else if (strncmp (line, STR_DL_DEPLIBS,
3242 sizeof (STR_DL_DEPLIBS) - 1) == 0) 3283 sizeof (STR_DL_DEPLIBS) - 1) == 0)
3243 { 3284 {
3244 errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); 3285 errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]);
3245 } 3286 }
3246 else if (strcmp (line, "installed=yes\n") == 0) 3287 else if (strcmp (line, "installed=yes\n") == 0)
3247 { 3288 {
3248 installed = 1; 3289 installed = 1;
3249 } 3290 }
3250 else if (strcmp (line, "installed=no\n") == 0) 3291 else if (strcmp (line, "installed=no\n") == 0)
3251 { 3292 {
3252 installed = 0; 3293 installed = 0;
3253 } 3294 }
3254 3295
3255#undef STR_LIBRARY_NAMES 3296#undef STR_LIBRARY_NAMES
3256#define STR_LIBRARY_NAMES "library_names=" 3297#define STR_LIBRARY_NAMES "library_names="
3257 else if (! dlname && strncmp (line, STR_LIBRARY_NAMES, 3298 else if (!dlname && strncmp (line, STR_LIBRARY_NAMES,
3258 sizeof (STR_LIBRARY_NAMES) - 1) == 0) 3299 sizeof (STR_LIBRARY_NAMES) - 1) == 0)
3259 { 3300 {
3260 char *last_libname; 3301 char *last_libname;
3261 errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); 3302 errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]);
3262 if (!errors 3303 if (!errors
3263 && dlname 3304 && dlname && (last_libname = strrchr (dlname, ' ')) != 0)
3264 && (last_libname = strrchr (dlname, ' ')) != 0) 3305 {
3265 { 3306 last_libname = lt_estrdup (last_libname + 1);
3266 last_libname = lt_estrdup (last_libname + 1); 3307 if (!last_libname)
3267 if (!last_libname) 3308 {
3268 { 3309 ++errors;
3269 ++errors; 3310 goto cleanup;
3270 goto cleanup; 3311 }
3271 } 3312 LT_DLMEM_REASSIGN (dlname, last_libname);
3272 LT_DLMEM_REASSIGN (dlname, last_libname); 3313 }
3273 } 3314 }
3274 } 3315
3275 3316 if (errors)
3276 if (errors) 3317 break;
3277 break; 3318 }
3278 }
3279 3319
3280 fclose (file); 3320 fclose (file);
3281 LT_DLFREE (line); 3321 LT_DLFREE (line);
@@ -3283,105 +3323,106 @@ try_dlopen (phandle, filename)
3283 /* allocate the handle */ 3323 /* allocate the handle */
3284 *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); 3324 *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
3285 if (*phandle == 0) 3325 if (*phandle == 0)
3286 ++errors; 3326 ++errors;
3287 3327
3288 if (errors) 3328 if (errors)
3289 { 3329 {
3290 free_vars (dlname, old_name, libdir, deplibs); 3330 free_vars (dlname, old_name, libdir, deplibs);
3291 LT_DLFREE (*phandle); 3331 LT_DLFREE (*phandle);
3292 goto cleanup; 3332 goto cleanup;
3293 } 3333 }
3294 3334
3295 assert (*phandle); 3335 assert (*phandle);
3296 3336
3297 memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); 3337 memset (*phandle, 0, sizeof (struct lt_dlhandle_struct));
3298 if (load_deplibs (*phandle, deplibs) == 0) 3338 if (load_deplibs (*phandle, deplibs) == 0)
3299 { 3339 {
3300 newhandle = *phandle; 3340 newhandle = *phandle;
3301 /* find_module may replace newhandle */ 3341 /* find_module may replace newhandle */
3302 if (find_module (&newhandle, dir, libdir, dlname, old_name, installed)) 3342 if (find_module
3303 { 3343 (&newhandle, dir, libdir, dlname, old_name, installed))
3304 unload_deplibs (*phandle); 3344 {
3305 ++errors; 3345 unload_deplibs (*phandle);
3306 } 3346 ++errors;
3307 } 3347 }
3348 }
3308 else 3349 else
3309 { 3350 {
3310 ++errors; 3351 ++errors;
3311 } 3352 }
3312 3353
3313 free_vars (dlname, old_name, libdir, deplibs); 3354 free_vars (dlname, old_name, libdir, deplibs);
3314 if (errors) 3355 if (errors)
3315 { 3356 {
3316 LT_DLFREE (*phandle); 3357 LT_DLFREE (*phandle);
3317 goto cleanup; 3358 goto cleanup;
3318 } 3359 }
3319 3360
3320 if (*phandle != newhandle) 3361 if (*phandle != newhandle)
3321 { 3362 {
3322 unload_deplibs (*phandle); 3363 unload_deplibs (*phandle);
3323 } 3364 }
3324 } 3365 }
3325 else 3366 else
3326 { 3367 {
3327 /* not a libtool module */ 3368 /* not a libtool module */
3328 *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); 3369 *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
3329 if (*phandle == 0) 3370 if (*phandle == 0)
3330 { 3371 {
3331 ++errors; 3372 ++errors;
3332 goto cleanup; 3373 goto cleanup;
3333 } 3374 }
3334 3375
3335 memset (*phandle, 0, sizeof (struct lt_dlhandle_struct)); 3376 memset (*phandle, 0, sizeof (struct lt_dlhandle_struct));
3336 newhandle = *phandle; 3377 newhandle = *phandle;
3337 3378
3338 /* If the module has no directory name component, try to find it 3379 /* If the module has no directory name component, try to find it
3339 first in user_search_path and then other prescribed paths. 3380 first in user_search_path and then other prescribed paths.
3340 Otherwise (or in any case if the module was not yet found) try 3381 Otherwise (or in any case if the module was not yet found) try
3341 opening just the module name as passed. */ 3382 opening just the module name as passed. */
3342 if ((dir || (!find_handle (user_search_path, base_name, &newhandle) 3383 if ((dir || (!find_handle (user_search_path, base_name, &newhandle)
3343 && !find_handle (getenv (LTDL_SEARCHPATH_VAR), base_name, 3384 && !find_handle (getenv (LTDL_SEARCHPATH_VAR), base_name,
3344 &newhandle) 3385 &newhandle)
3345#ifdef LTDL_SHLIBPATH_VAR 3386#ifdef LTDL_SHLIBPATH_VAR
3346 && !find_handle (getenv (LTDL_SHLIBPATH_VAR), base_name, 3387 && !find_handle (getenv (LTDL_SHLIBPATH_VAR), base_name,
3347 &newhandle) 3388 &newhandle)
3348#endif 3389#endif
3349#ifdef LTDL_SYSSEARCHPATH 3390#ifdef LTDL_SYSSEARCHPATH
3350 && !find_handle (sys_search_path, base_name, &newhandle) 3391 && !find_handle (sys_search_path, base_name, &newhandle)
3351#endif 3392#endif
3352 ))) 3393 )))
3353 { 3394 {
3354 if (tryall_dlopen (&newhandle, filename) != 0) 3395 if (tryall_dlopen (&newhandle, filename) != 0)
3355 { 3396 {
3356 newhandle = NULL; 3397 newhandle = NULL;
3357 } 3398 }
3358 } 3399 }
3359 3400
3360 if (!newhandle) 3401 if (!newhandle)
3361 { 3402 {
3362 LT_DLFREE (*phandle); 3403 LT_DLFREE (*phandle);
3363 ++errors; 3404 ++errors;
3364 goto cleanup; 3405 goto cleanup;
3365 } 3406 }
3366 } 3407 }
3367 3408
3368 register_handle: 3409register_handle:
3369 LT_DLMEM_REASSIGN (*phandle, newhandle); 3410 LT_DLMEM_REASSIGN (*phandle, newhandle);
3370 3411
3371 if ((*phandle)->info.ref_count == 0) 3412 if ((*phandle)->info.ref_count == 0)
3372 { 3413 {
3373 (*phandle)->info.ref_count = 1; 3414 (*phandle)->info.ref_count = 1;
3374 LT_DLMEM_REASSIGN ((*phandle)->info.name, name); 3415 LT_DLMEM_REASSIGN ((*phandle)->info.name, name);
3375 3416
3376 LT_DLMUTEX_LOCK (); 3417 LT_DLMUTEX_LOCK ();
3377 (*phandle)->next = handles; 3418 (*phandle)->next = handles;
3378 handles = *phandle; 3419 handles = *phandle;
3379 LT_DLMUTEX_UNLOCK (); 3420 LT_DLMUTEX_UNLOCK ();
3380 } 3421 }
3381 3422
3382 LT_DLMUTEX_SETERROR (saved_error); 3423 LT_DLMUTEX_SETERROR (saved_error);
3383 3424
3384 cleanup: 3425cleanup:
3385 LT_DLFREE (dir); 3426 LT_DLFREE (dir);
3386 LT_DLFREE (name); 3427 LT_DLFREE (name);
3387 LT_DLFREE (canonical); 3428 LT_DLFREE (canonical);
@@ -3425,11 +3466,11 @@ lt_dlhandle
3425lt_dlopenext (filename) 3466lt_dlopenext (filename)
3426 const char *filename; 3467 const char *filename;
3427{ 3468{
3428 lt_dlhandle handle = 0; 3469 lt_dlhandle handle = 0;
3429 char * tmp = 0; 3470 char *tmp = 0;
3430 char * ext = 0; 3471 char *ext = 0;
3431 size_t len; 3472 size_t len;
3432 int errors = 0; 3473 int errors = 0;
3433 3474
3434 if (!filename) 3475 if (!filename)
3435 { 3476 {
@@ -3445,7 +3486,7 @@ lt_dlopenext (filename)
3445 to try appending additional extensions. */ 3486 to try appending additional extensions. */
3446 if (ext && ((strcmp (ext, archive_ext) == 0) 3487 if (ext && ((strcmp (ext, archive_ext) == 0)
3447#ifdef LTDL_SHLIB_EXT 3488#ifdef LTDL_SHLIB_EXT
3448 || (strcmp (ext, shlib_ext) == 0) 3489 || (strcmp (ext, shlib_ext) == 0)
3449#endif 3490#endif
3450 )) 3491 ))
3451 { 3492 {
@@ -3479,7 +3520,7 @@ lt_dlopenext (filename)
3479 LT_DLFREE (tmp); 3520 LT_DLFREE (tmp);
3480 tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1); 3521 tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1);
3481 if (!tmp) 3522 if (!tmp)
3482 return 0; 3523 return 0;
3483 3524
3484 strcpy (tmp, filename); 3525 strcpy (tmp, filename);
3485 } 3526 }
@@ -3488,7 +3529,7 @@ lt_dlopenext (filename)
3488 tmp[len] = LT_EOS_CHAR; 3529 tmp[len] = LT_EOS_CHAR;
3489 } 3530 }
3490 3531
3491 strcat(tmp, shlib_ext); 3532 strcat (tmp, shlib_ext);
3492 errors = try_dlopen (&handle, tmp); 3533 errors = try_dlopen (&handle, tmp);
3493 3534
3494 /* As before, if the file was found but loading failed, return now 3535 /* As before, if the file was found but loading failed, return now
@@ -3520,14 +3561,14 @@ lt_argz_insert (pargz, pargz_len, before, entry)
3520 if ((error = argz_insert (pargz, pargz_len, before, entry))) 3561 if ((error = argz_insert (pargz, pargz_len, before, entry)))
3521 { 3562 {
3522 switch (error) 3563 switch (error)
3523 { 3564 {
3524 case ENOMEM: 3565 case ENOMEM:
3525 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); 3566 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
3526 break; 3567 break;
3527 default: 3568 default:
3528 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); 3569 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN));
3529 break; 3570 break;
3530 } 3571 }
3531 return 1; 3572 return 1;
3532 } 3573 }
3533 3574
@@ -3549,10 +3590,12 @@ lt_argz_insertinorder (pargz, pargz_len, entry)
3549 if (*pargz) 3590 if (*pargz)
3550 while ((before = argz_next (*pargz, *pargz_len, before))) 3591 while ((before = argz_next (*pargz, *pargz_len, before)))
3551 { 3592 {
3552 int cmp = strcmp (entry, before); 3593 int cmp = strcmp (entry, before);
3553 3594
3554 if (cmp < 0) break; 3595 if (cmp < 0)
3555 if (cmp == 0) return 0; /* No duplicates! */ 3596 break;
3597 if (cmp == 0)
3598 return 0; /* No duplicates! */
3556 } 3599 }
3557 3600
3558 return lt_argz_insert (pargz, pargz_len, before, entry); 3601 return lt_argz_insert (pargz, pargz_len, before, entry);
@@ -3565,26 +3608,26 @@ lt_argz_insertdir (pargz, pargz_len, dirnam, dp)
3565 const char *dirnam; 3608 const char *dirnam;
3566 struct dirent *dp; 3609 struct dirent *dp;
3567{ 3610{
3568 char *buf = 0; 3611 char *buf = 0;
3569 size_t buf_len = 0; 3612 size_t buf_len = 0;
3570 char *end = 0; 3613 char *end = 0;
3571 size_t end_offset = 0; 3614 size_t end_offset = 0;
3572 size_t dir_len = 0; 3615 size_t dir_len = 0;
3573 int errors = 0; 3616 int errors = 0;
3574 3617
3575 assert (pargz); 3618 assert (pargz);
3576 assert (pargz_len); 3619 assert (pargz_len);
3577 assert (dp); 3620 assert (dp);
3578 3621
3579 dir_len = LT_STRLEN (dirnam); 3622 dir_len = LT_STRLEN (dirnam);
3580 end = dp->d_name + LT_D_NAMLEN(dp); 3623 end = dp->d_name + LT_D_NAMLEN (dp);
3581 3624
3582 /* Ignore version numbers. */ 3625 /* Ignore version numbers. */
3583 { 3626 {
3584 char *p; 3627 char *p;
3585 for (p = end; p -1 > dp->d_name; --p) 3628 for (p = end; p - 1 > dp->d_name; --p)
3586 if (strchr (".0123456789", p[-1]) == 0) 3629 if (strchr (".0123456789", p[-1]) == 0)
3587 break; 3630 break;
3588 3631
3589 if (*p == '.') 3632 if (*p == '.')
3590 end = p; 3633 end = p;
@@ -3593,25 +3636,25 @@ lt_argz_insertdir (pargz, pargz_len, dirnam, dp)
3593 /* Ignore filename extension. */ 3636 /* Ignore filename extension. */
3594 { 3637 {
3595 char *p; 3638 char *p;
3596 for (p = end -1; p > dp->d_name; --p) 3639 for (p = end - 1; p > dp->d_name; --p)
3597 if (*p == '.') 3640 if (*p == '.')
3598 { 3641 {
3599 end = p; 3642 end = p;
3600 break; 3643 break;
3601 } 3644 }
3602 } 3645 }
3603 3646
3604 /* Prepend the directory name. */ 3647 /* Prepend the directory name. */
3605 end_offset = end - dp->d_name; 3648 end_offset = end - dp->d_name;
3606 buf_len = dir_len + 1+ end_offset; 3649 buf_len = dir_len + 1 + end_offset;
3607 buf = LT_EMALLOC (char, 1+ buf_len); 3650 buf = LT_EMALLOC (char, 1 + buf_len);
3608 if (!buf) 3651 if (!buf)
3609 return ++errors; 3652 return ++errors;
3610 3653
3611 assert (buf); 3654 assert (buf);
3612 3655
3613 strcpy (buf, dirnam); 3656 strcpy (buf, dirnam);
3614 strcat (buf, "/"); 3657 strcat (buf, "/");
3615 strncat (buf, dp->d_name, end_offset); 3658 strncat (buf, dp->d_name, end_offset);
3616 buf[buf_len] = LT_EOS_CHAR; 3659 buf[buf_len] = LT_EOS_CHAR;
3617 3660
@@ -3630,26 +3673,26 @@ list_files_by_dir (dirnam, pargz, pargz_len)
3630 char **pargz; 3673 char **pargz;
3631 size_t *pargz_len; 3674 size_t *pargz_len;
3632{ 3675{
3633 DIR *dirp = 0; 3676 DIR *dirp = 0;
3634 int errors = 0; 3677 int errors = 0;
3635 3678
3636 assert (dirnam && *dirnam); 3679 assert (dirnam && *dirnam);
3637 assert (pargz); 3680 assert (pargz);
3638 assert (pargz_len); 3681 assert (pargz_len);
3639 assert (dirnam[LT_STRLEN(dirnam) -1] != '/'); 3682 assert (dirnam[LT_STRLEN (dirnam) - 1] != '/');
3640 3683
3641 dirp = opendir (dirnam); 3684 dirp = opendir (dirnam);
3642 if (dirp) 3685 if (dirp)
3643 { 3686 {
3644 struct dirent *dp = 0; 3687 struct dirent *dp = 0;
3645 3688
3646 while ((dp = readdir (dirp))) 3689 while ((dp = readdir (dirp)))
3647 if (dp->d_name[0] != '.') 3690 if (dp->d_name[0] != '.')
3648 if (lt_argz_insertdir (pargz, pargz_len, dirnam, dp)) 3691 if (lt_argz_insertdir (pargz, pargz_len, dirnam, dp))
3649 { 3692 {
3650 ++errors; 3693 ++errors;
3651 break; 3694 break;
3652 } 3695 }
3653 3696
3654 closedir (dirp); 3697 closedir (dirp);
3655 } 3698 }
@@ -3668,12 +3711,12 @@ foreachfile_callback (dirname, data1, data2)
3668 lt_ptr data1; 3711 lt_ptr data1;
3669 lt_ptr data2; 3712 lt_ptr data2;
3670{ 3713{
3671 int (*func) LT_PARAMS((const char *filename, lt_ptr data)) 3714 int (*func) LT_PARAMS ((const char *filename, lt_ptr data))
3672 = (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1; 3715 = (int (*)LT_PARAMS ((const char *filename, lt_ptr data))) data1;
3673 3716
3674 int is_done = 0; 3717 int is_done = 0;
3675 char *argz = 0; 3718 char *argz = 0;
3676 size_t argz_len = 0; 3719 size_t argz_len = 0;
3677 3720
3678 if (list_files_by_dir (dirname, &argz, &argz_len) != 0) 3721 if (list_files_by_dir (dirname, &argz, &argz_len) != 0)
3679 goto cleanup; 3722 goto cleanup;
@@ -3684,10 +3727,10 @@ foreachfile_callback (dirname, data1, data2)
3684 char *filename = 0; 3727 char *filename = 0;
3685 while ((filename = argz_next (argz, argz_len, filename))) 3728 while ((filename = argz_next (argz, argz_len, filename)))
3686 if ((is_done = (*func) (filename, data2))) 3729 if ((is_done = (*func) (filename, data2)))
3687 break; 3730 break;
3688 } 3731 }
3689 3732
3690 cleanup: 3733cleanup:
3691 LT_DLFREE (argz); 3734 LT_DLFREE (argz);
3692 3735
3693 return is_done; 3736 return is_done;
@@ -3711,34 +3754,34 @@ lt_dlforeachfile (search_path, func, data)
3711 if (search_path) 3754 if (search_path)
3712 { 3755 {
3713 /* If a specific path was passed, search only the directories 3756 /* If a specific path was passed, search only the directories
3714 listed in it. */ 3757 listed in it. */
3715 is_done = foreach_dirinpath (search_path, 0, 3758 is_done = foreach_dirinpath (search_path, 0,
3716 foreachfile_callback, func, data); 3759 foreachfile_callback, func, data);
3717 } 3760 }
3718 else 3761 else
3719 { 3762 {
3720 /* Otherwise search the default paths. */ 3763 /* Otherwise search the default paths. */
3721 is_done = foreach_dirinpath (user_search_path, 0, 3764 is_done = foreach_dirinpath (user_search_path, 0,
3722 foreachfile_callback, func, data); 3765 foreachfile_callback, func, data);
3723 if (!is_done) 3766 if (!is_done)
3724 { 3767 {
3725 is_done = foreach_dirinpath (getenv("LTDL_LIBRARY_PATH"), 0, 3768 is_done = foreach_dirinpath (getenv ("LTDL_LIBRARY_PATH"), 0,
3726 foreachfile_callback, func, data); 3769 foreachfile_callback, func, data);
3727 } 3770 }
3728 3771
3729#ifdef LTDL_SHLIBPATH_VAR 3772#ifdef LTDL_SHLIBPATH_VAR
3730 if (!is_done) 3773 if (!is_done)
3731 { 3774 {
3732 is_done = foreach_dirinpath (getenv(LTDL_SHLIBPATH_VAR), 0, 3775 is_done = foreach_dirinpath (getenv (LTDL_SHLIBPATH_VAR), 0,
3733 foreachfile_callback, func, data); 3776 foreachfile_callback, func, data);
3734 } 3777 }
3735#endif 3778#endif
3736#ifdef LTDL_SYSSEARCHPATH 3779#ifdef LTDL_SYSSEARCHPATH
3737 if (!is_done) 3780 if (!is_done)
3738 { 3781 {
3739 is_done = foreach_dirinpath (getenv(LTDL_SYSSEARCHPATH), 0, 3782 is_done = foreach_dirinpath (getenv (LTDL_SYSSEARCHPATH), 0,
3740 foreachfile_callback, func, data); 3783 foreachfile_callback, func, data);
3741 } 3784 }
3742#endif 3785#endif
3743 } 3786 }
3744 3787
@@ -3780,16 +3823,16 @@ lt_dlclose (handle)
3780 lt_user_data data = handle->loader->dlloader_data; 3823 lt_user_data data = handle->loader->dlloader_data;
3781 3824
3782 if (handle != handles) 3825 if (handle != handles)
3783 { 3826 {
3784 last->next = handle->next; 3827 last->next = handle->next;
3785 } 3828 }
3786 else 3829 else
3787 { 3830 {
3788 handles = handle->next; 3831 handles = handle->next;
3789 } 3832 }
3790 3833
3791 errors += handle->loader->module_close (data, handle->module); 3834 errors += handle->loader->module_close (data, handle->module);
3792 errors += unload_deplibs(handle); 3835 errors += unload_deplibs (handle);
3793 3836
3794 /* It is up to the callers to free the data itself. */ 3837 /* It is up to the callers to free the data itself. */
3795 LT_DLFREE (handle->caller_data); 3838 LT_DLFREE (handle->caller_data);
@@ -3807,7 +3850,7 @@ lt_dlclose (handle)
3807 ++errors; 3850 ++errors;
3808 } 3851 }
3809 3852
3810 done: 3853done:
3811 LT_DLMUTEX_UNLOCK (); 3854 LT_DLMUTEX_UNLOCK ();
3812 3855
3813 return errors; 3856 return errors;
@@ -3819,8 +3862,8 @@ lt_dlsym (handle, symbol)
3819 const char *symbol; 3862 const char *symbol;
3820{ 3863{
3821 size_t lensym; 3864 size_t lensym;
3822 char lsym[LT_SYMBOL_LENGTH]; 3865 char lsym[LT_SYMBOL_LENGTH];
3823 char *sym; 3866 char *sym;
3824 lt_ptr address; 3867 lt_ptr address;
3825 lt_user_data data; 3868 lt_user_data data;
3826 3869
@@ -3837,7 +3880,7 @@ lt_dlsym (handle, symbol)
3837 } 3880 }
3838 3881
3839 lensym = LT_STRLEN (symbol) + LT_STRLEN (handle->loader->sym_prefix) 3882 lensym = LT_STRLEN (symbol) + LT_STRLEN (handle->loader->sym_prefix)
3840 + LT_STRLEN (handle->info.name); 3883 + LT_STRLEN (handle->info.name);
3841 3884
3842 if (lensym + LT_SYMBOL_OVERHEAD < LT_SYMBOL_LENGTH) 3885 if (lensym + LT_SYMBOL_OVERHEAD < LT_SYMBOL_LENGTH)
3843 { 3886 {
@@ -3847,10 +3890,10 @@ lt_dlsym (handle, symbol)
3847 { 3890 {
3848 sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1); 3891 sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1);
3849 if (!sym) 3892 if (!sym)
3850 { 3893 {
3851 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW)); 3894 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW));
3852 return 0; 3895 return 0;
3853 } 3896 }
3854 } 3897 }
3855 3898
3856 data = handle->loader->dlloader_data; 3899 data = handle->loader->dlloader_data;
@@ -3862,40 +3905,40 @@ lt_dlsym (handle, symbol)
3862 3905
3863 /* this is a libtool module */ 3906 /* this is a libtool module */
3864 if (handle->loader->sym_prefix) 3907 if (handle->loader->sym_prefix)
3865 { 3908 {
3866 strcpy(sym, handle->loader->sym_prefix); 3909 strcpy (sym, handle->loader->sym_prefix);
3867 strcat(sym, handle->info.name); 3910 strcat (sym, handle->info.name);
3868 } 3911 }
3869 else 3912 else
3870 { 3913 {
3871 strcpy(sym, handle->info.name); 3914 strcpy (sym, handle->info.name);
3872 } 3915 }
3873 3916
3874 strcat(sym, "_LTX_"); 3917 strcat (sym, "_LTX_");
3875 strcat(sym, symbol); 3918 strcat (sym, symbol);
3876 3919
3877 /* try "modulename_LTX_symbol" */ 3920 /* try "modulename_LTX_symbol" */
3878 address = handle->loader->find_sym (data, handle->module, sym); 3921 address = handle->loader->find_sym (data, handle->module, sym);
3879 if (address) 3922 if (address)
3880 { 3923 {
3881 if (sym != lsym) 3924 if (sym != lsym)
3882 { 3925 {
3883 LT_DLFREE (sym); 3926 LT_DLFREE (sym);
3884 } 3927 }
3885 return address; 3928 return address;
3886 } 3929 }
3887 LT_DLMUTEX_SETERROR (saved_error); 3930 LT_DLMUTEX_SETERROR (saved_error);
3888 } 3931 }
3889 3932
3890 /* otherwise try "symbol" */ 3933 /* otherwise try "symbol" */
3891 if (handle->loader->sym_prefix) 3934 if (handle->loader->sym_prefix)
3892 { 3935 {
3893 strcpy(sym, handle->loader->sym_prefix); 3936 strcpy (sym, handle->loader->sym_prefix);
3894 strcat(sym, symbol); 3937 strcat (sym, symbol);
3895 } 3938 }
3896 else 3939 else
3897 { 3940 {
3898 strcpy(sym, symbol); 3941 strcpy (sym, symbol);
3899 } 3942 }
3900 3943
3901 address = handle->loader->find_sym (data, handle->module, sym); 3944 address = handle->loader->find_sym (data, handle->module, sym);
@@ -3924,10 +3967,10 @@ lt_dlpath_insertdir (ppath, before, dir)
3924 char *before; 3967 char *before;
3925 const char *dir; 3968 const char *dir;
3926{ 3969{
3927 int errors = 0; 3970 int errors = 0;
3928 char *canonical = 0; 3971 char *canonical = 0;
3929 char *argz = 0; 3972 char *argz = 0;
3930 size_t argz_len = 0; 3973 size_t argz_len = 0;
3931 3974
3932 assert (ppath); 3975 assert (ppath);
3933 assert (dir && *dir); 3976 assert (dir && *dir);
@@ -3943,12 +3986,12 @@ lt_dlpath_insertdir (ppath, before, dir)
3943 /* If *PPATH is empty, set it to DIR. */ 3986 /* If *PPATH is empty, set it to DIR. */
3944 if (*ppath == 0) 3987 if (*ppath == 0)
3945 { 3988 {
3946 assert (!before); /* BEFORE cannot be set without PPATH. */ 3989 assert (!before); /* BEFORE cannot be set without PPATH. */
3947 assert (dir); /* Without DIR, don't call this function! */ 3990 assert (dir); /* Without DIR, don't call this function! */
3948 3991
3949 *ppath = lt_estrdup (dir); 3992 *ppath = lt_estrdup (dir);
3950 if (*ppath == 0) 3993 if (*ppath == 0)
3951 ++errors; 3994 ++errors;
3952 3995
3953 return errors; 3996 return errors;
3954 } 3997 }
@@ -3981,9 +4024,9 @@ lt_dlpath_insertdir (ppath, before, dir)
3981 } 4024 }
3982 4025
3983 argz_stringify (argz, argz_len, LT_PATHSEP_CHAR); 4026 argz_stringify (argz, argz_len, LT_PATHSEP_CHAR);
3984 LT_DLMEM_REASSIGN (*ppath, argz); 4027 LT_DLMEM_REASSIGN (*ppath, argz);
3985 4028
3986 cleanup: 4029cleanup:
3987 LT_DLFREE (canonical); 4030 LT_DLFREE (canonical);
3988 LT_DLFREE (argz); 4031 LT_DLFREE (argz);
3989 4032
@@ -4000,7 +4043,7 @@ lt_dladdsearchdir (search_dir)
4000 { 4043 {
4001 LT_DLMUTEX_LOCK (); 4044 LT_DLMUTEX_LOCK ();
4002 if (lt_dlpath_insertdir (&user_search_path, 0, search_dir) != 0) 4045 if (lt_dlpath_insertdir (&user_search_path, 0, search_dir) != 0)
4003 ++errors; 4046 ++errors;
4004 LT_DLMUTEX_UNLOCK (); 4047 LT_DLMUTEX_UNLOCK ();
4005 } 4048 }
4006 4049
@@ -4018,12 +4061,12 @@ lt_dlinsertsearchdir (before, search_dir)
4018 { 4061 {
4019 LT_DLMUTEX_LOCK (); 4062 LT_DLMUTEX_LOCK ();
4020 if ((before < user_search_path) 4063 if ((before < user_search_path)
4021 || (before >= user_search_path + LT_STRLEN (user_search_path))) 4064 || (before >= user_search_path + LT_STRLEN (user_search_path)))
4022 { 4065 {
4023 LT_DLMUTEX_UNLOCK (); 4066 LT_DLMUTEX_UNLOCK ();
4024 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_POSITION)); 4067 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_POSITION));
4025 return 1; 4068 return 1;
4026 } 4069 }
4027 LT_DLMUTEX_UNLOCK (); 4070 LT_DLMUTEX_UNLOCK ();
4028 } 4071 }
4029 4072
@@ -4031,10 +4074,10 @@ lt_dlinsertsearchdir (before, search_dir)
4031 { 4074 {
4032 LT_DLMUTEX_LOCK (); 4075 LT_DLMUTEX_LOCK ();
4033 if (lt_dlpath_insertdir (&user_search_path, 4076 if (lt_dlpath_insertdir (&user_search_path,
4034 (char *) before, search_dir) != 0) 4077 (char *) before, search_dir) != 0)
4035 { 4078 {
4036 ++errors; 4079 ++errors;
4037 } 4080 }
4038 LT_DLMUTEX_UNLOCK (); 4081 LT_DLMUTEX_UNLOCK ();
4039 } 4082 }
4040 4083
@@ -4045,7 +4088,7 @@ int
4045lt_dlsetsearchpath (search_path) 4088lt_dlsetsearchpath (search_path)
4046 const char *search_path; 4089 const char *search_path;
4047{ 4090{
4048 int errors = 0; 4091 int errors = 0;
4049 4092
4050 LT_DLMUTEX_LOCK (); 4093 LT_DLMUTEX_LOCK ();
4051 LT_DLFREE (user_search_path); 4094 LT_DLFREE (user_search_path);
@@ -4096,7 +4139,7 @@ lt_dlmakeresident (handle)
4096} 4139}
4097 4140
4098int 4141int
4099lt_dlisresident (handle) 4142lt_dlisresident (handle)
4100 lt_dlhandle handle; 4143 lt_dlhandle handle;
4101{ 4144{
4102 if (!handle) 4145 if (!handle)
@@ -4107,10 +4150,10 @@ lt_dlisresident (handle)
4107 4150
4108 return LT_DLIS_RESIDENT (handle); 4151 return LT_DLIS_RESIDENT (handle);
4109} 4152}
4153
4110 4154
4111 4155
4112 4156
4113
4114/* --- MODULE INFORMATION --- */ 4157/* --- MODULE INFORMATION --- */
4115 4158
4116const lt_dlinfo * 4159const lt_dlinfo *
@@ -4135,7 +4178,7 @@ lt_dlhandle_next (place)
4135 4178
4136int 4179int
4137lt_dlforeach (func, data) 4180lt_dlforeach (func, data)
4138 int (*func) LT_PARAMS((lt_dlhandle handle, lt_ptr data)); 4181 int (*func) LT_PARAMS ((lt_dlhandle handle, lt_ptr data));
4139 lt_ptr data; 4182 lt_ptr data;
4140{ 4183{
4141 int errors = 0; 4184 int errors = 0;
@@ -4150,10 +4193,10 @@ lt_dlforeach (func, data)
4150 4193
4151 cur = cur->next; 4194 cur = cur->next;
4152 if ((*func) (tmp, data)) 4195 if ((*func) (tmp, data))
4153 { 4196 {
4154 ++errors; 4197 ++errors;
4155 break; 4198 break;
4156 } 4199 }
4157 } 4200 }
4158 4201
4159 LT_DLMUTEX_UNLOCK (); 4202 LT_DLMUTEX_UNLOCK ();
@@ -4195,10 +4238,10 @@ lt_dlcaller_set_data (key, handle, data)
4195 for (i = 0; i < n_elements; ++i) 4238 for (i = 0; i < n_elements; ++i)
4196 { 4239 {
4197 if (handle->caller_data[i].key == key) 4240 if (handle->caller_data[i].key == key)
4198 { 4241 {
4199 stale = handle->caller_data[i].data; 4242 stale = handle->caller_data[i].data;
4200 break; 4243 break;
4201 } 4244 }
4202 } 4245 }
4203 4246
4204 /* Ensure that there is enough room in this handle's caller_data 4247 /* Ensure that there is enough room in this handle's caller_data
@@ -4206,31 +4249,31 @@ lt_dlcaller_set_data (key, handle, data)
4206 if (i == n_elements) 4249 if (i == n_elements)
4207 { 4250 {
4208 lt_caller_data *temp 4251 lt_caller_data *temp
4209 = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); 4252 = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2 + n_elements);
4210 4253
4211 if (!temp) 4254 if (!temp)
4212 { 4255 {
4213 stale = 0; 4256 stale = 0;
4214 goto done; 4257 goto done;
4215 } 4258 }
4216 4259
4217 handle->caller_data = temp; 4260 handle->caller_data = temp;
4218 4261
4219 /* We only need this if we needed to allocate a new caller_data. */ 4262 /* We only need this if we needed to allocate a new caller_data. */
4220 handle->caller_data[i].key = key; 4263 handle->caller_data[i].key = key;
4221 handle->caller_data[1+ i].key = 0; 4264 handle->caller_data[1 + i].key = 0;
4222 } 4265 }
4223 4266
4224 handle->caller_data[i].data = data; 4267 handle->caller_data[i].data = data;
4225 4268
4226 done: 4269done:
4227 LT_DLMUTEX_UNLOCK (); 4270 LT_DLMUTEX_UNLOCK ();
4228 4271
4229 return stale; 4272 return stale;
4230} 4273}
4231 4274
4232lt_ptr 4275lt_ptr
4233lt_dlcaller_get_data (key, handle) 4276lt_dlcaller_get_data (key, handle)
4234 lt_dlcaller_id key; 4277 lt_dlcaller_id key;
4235 lt_dlhandle handle; 4278 lt_dlhandle handle;
4236{ 4279{
@@ -4245,11 +4288,11 @@ lt_dlcaller_get_data (key, handle)
4245 int i; 4288 int i;
4246 for (i = 0; handle->caller_data[i].key; ++i) 4289 for (i = 0; handle->caller_data[i].key; ++i)
4247 { 4290 {
4248 if (handle->caller_data[i].key == key) 4291 if (handle->caller_data[i].key == key)
4249 { 4292 {
4250 result = handle->caller_data[i].data; 4293 result = handle->caller_data[i].data;
4251 break; 4294 break;
4252 } 4295 }
4253 } 4296 }
4254 } 4297 }
4255 4298
@@ -4257,9 +4300,9 @@ lt_dlcaller_get_data (key, handle)
4257 4300
4258 return result; 4301 return result;
4259} 4302}
4303
4260 4304
4261 4305
4262
4263/* --- USER MODULE LOADER API --- */ 4306/* --- USER MODULE LOADER API --- */
4264 4307
4265 4308
@@ -4272,10 +4315,9 @@ lt_dlloader_add (place, dlloader, loader_name)
4272 int errors = 0; 4315 int errors = 0;
4273 lt_dlloader *node = 0, *ptr = 0; 4316 lt_dlloader *node = 0, *ptr = 0;
4274 4317
4275 if ((dlloader == 0) /* diagnose null parameters */ 4318 if ((dlloader == 0) /* diagnose null parameters */
4276 || (dlloader->module_open == 0) 4319 || (dlloader->module_open == 0)
4277 || (dlloader->module_close == 0) 4320 || (dlloader->module_close == 0) || (dlloader->find_sym == 0))
4278 || (dlloader->find_sym == 0))
4279 { 4321 {
4280 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); 4322 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));
4281 return 1; 4323 return 1;
@@ -4286,14 +4328,14 @@ lt_dlloader_add (place, dlloader, loader_name)
4286 if (!node) 4328 if (!node)
4287 return 1; 4329 return 1;
4288 4330
4289 node->next = 0; 4331 node->next = 0;
4290 node->loader_name = loader_name; 4332 node->loader_name = loader_name;
4291 node->sym_prefix = dlloader->sym_prefix; 4333 node->sym_prefix = dlloader->sym_prefix;
4292 node->dlloader_exit = dlloader->dlloader_exit; 4334 node->dlloader_exit = dlloader->dlloader_exit;
4293 node->module_open = dlloader->module_open; 4335 node->module_open = dlloader->module_open;
4294 node->module_close = dlloader->module_close; 4336 node->module_close = dlloader->module_close;
4295 node->find_sym = dlloader->find_sym; 4337 node->find_sym = dlloader->find_sym;
4296 node->dlloader_data = dlloader->dlloader_data; 4338 node->dlloader_data = dlloader->dlloader_data;
4297 4339
4298 LT_DLMUTEX_LOCK (); 4340 LT_DLMUTEX_LOCK ();
4299 if (!loaders) 4341 if (!loaders)
@@ -4304,11 +4346,11 @@ lt_dlloader_add (place, dlloader, loader_name)
4304 else if (!place) 4346 else if (!place)
4305 { 4347 {
4306 /* If PLACE is not set, add NODE to the end of the 4348 /* If PLACE is not set, add NODE to the end of the
4307 LOADERS list. */ 4349 LOADERS list. */
4308 for (ptr = loaders; ptr->next; ptr = ptr->next) 4350 for (ptr = loaders; ptr->next; ptr = ptr->next)
4309 { 4351 {
4310 /*NOWORK*/; 4352 /*NOWORK*/;
4311 } 4353 }
4312 4354
4313 ptr->next = node; 4355 ptr->next = node;
4314 } 4356 }
@@ -4322,21 +4364,21 @@ lt_dlloader_add (place, dlloader, loader_name)
4322 { 4364 {
4323 /* Find the node immediately preceding PLACE. */ 4365 /* Find the node immediately preceding PLACE. */
4324 for (ptr = loaders; ptr->next != place; ptr = ptr->next) 4366 for (ptr = loaders; ptr->next != place; ptr = ptr->next)
4325 { 4367 {
4326 /*NOWORK*/; 4368 /*NOWORK*/;
4327 } 4369 }
4328 4370
4329 if (ptr->next != place) 4371 if (ptr->next != place)
4330 { 4372 {
4331 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); 4373 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));
4332 ++errors; 4374 ++errors;
4333 } 4375 }
4334 else 4376 else
4335 { 4377 {
4336 /* Insert NODE between PTR and PLACE. */ 4378 /* Insert NODE between PTR and PLACE. */
4337 node->next = place; 4379 node->next = place;
4338 ptr->next = node; 4380 ptr->next = node;
4339 } 4381 }
4340 } 4382 }
4341 4383
4342 LT_DLMUTEX_UNLOCK (); 4384 LT_DLMUTEX_UNLOCK ();
@@ -4361,14 +4403,14 @@ lt_dlloader_remove (loader_name)
4361 LT_DLMUTEX_LOCK (); 4403 LT_DLMUTEX_LOCK ();
4362 4404
4363 /* Fail if there are any open modules which use this loader. */ 4405 /* Fail if there are any open modules which use this loader. */
4364 for (handle = handles; handle; handle = handle->next) 4406 for (handle = handles; handle; handle = handle->next)
4365 { 4407 {
4366 if (handle->loader == place) 4408 if (handle->loader == place)
4367 { 4409 {
4368 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER)); 4410 LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER));
4369 ++errors; 4411 ++errors;
4370 goto done; 4412 goto done;
4371 } 4413 }
4372 } 4414 }
4373 4415
4374 if (place == loaders) 4416 if (place == loaders)
@@ -4381,12 +4423,12 @@ lt_dlloader_remove (loader_name)
4381 /* Find the loader before the one being removed. */ 4423 /* Find the loader before the one being removed. */
4382 lt_dlloader *prev; 4424 lt_dlloader *prev;
4383 for (prev = loaders; prev->next; prev = prev->next) 4425 for (prev = loaders; prev->next; prev = prev->next)
4384 { 4426 {
4385 if (!strcmp (prev->next->loader_name, loader_name)) 4427 if (!strcmp (prev->next->loader_name, loader_name))
4386 { 4428 {
4387 break; 4429 break;
4388 } 4430 }
4389 } 4431 }
4390 4432
4391 place = prev->next; 4433 place = prev->next;
4392 prev->next = prev->next->next; 4434 prev->next = prev->next->next;
@@ -4399,7 +4441,7 @@ lt_dlloader_remove (loader_name)
4399 4441
4400 LT_DLFREE (place); 4442 LT_DLFREE (place);
4401 4443
4402 done: 4444done:
4403 LT_DLMUTEX_UNLOCK (); 4445 LT_DLMUTEX_UNLOCK ();
4404 4446
4405 return errors; 4447 return errors;
@@ -4468,9 +4510,9 @@ lt_dlloader_find (loader_name)
4468 for (place = loaders; place; place = place->next) 4510 for (place = loaders; place; place = place->next)
4469 { 4511 {
4470 if (strcmp (place->loader_name, loader_name) == 0) 4512 if (strcmp (place->loader_name, loader_name) == 0)
4471 { 4513 {
4472 break; 4514 break;
4473 } 4515 }
4474 } 4516 }
4475 LT_DLMUTEX_UNLOCK (); 4517 LT_DLMUTEX_UNLOCK ();
4476 4518