451 |
|
|
452 |
/* Make a copy of STR, but replacing each occurence of |
/* Make a copy of STR, but replacing each occurence of |
453 |
DELIM with '\0'. */ |
DELIM with '\0'. */ |
454 |
argz_len = LT_STRLEN (str); |
argz_len = 1+ LT_STRLEN (str); |
455 |
if (argz_len) |
if (argz_len) |
456 |
{ |
{ |
457 |
const char *p; |
const char *p; |
458 |
char *q; |
char *q; |
459 |
|
|
460 |
argz = LT_DLMALLOC (char, 1+ argz_len); |
argz = LT_DLMALLOC (char, argz_len); |
461 |
if (!argz) |
if (!argz) |
462 |
return ENOMEM; |
return ENOMEM; |
463 |
|
|
475 |
else |
else |
476 |
*q++ = *p; |
*q++ = *p; |
477 |
} |
} |
478 |
|
/* Copy terminating LT_EOS_CHAR. */ |
479 |
|
*q = *p; |
480 |
} |
} |
481 |
|
|
482 |
/* If ARGZ_LEN has shrunk to nothing, release ARGZ's memory. */ |
/* If ARGZ_LEN has shrunk to nothing, release ARGZ's memory. */ |
615 |
|
|
616 |
if (sep) |
if (sep) |
617 |
{ |
{ |
618 |
while (--argz_len >= 0) |
--argz_len; /* don't stringify the terminating EOS */ |
619 |
|
while (--argz_len > 0) |
620 |
{ |
{ |
621 |
if (argz[argz_len] == LT_EOS_CHAR) |
if (argz[argz_len] == LT_EOS_CHAR) |
622 |
argz[argz_len] = sep; |
argz[argz_len] = sep; |
827 |
else if (errindex < LT_ERROR_MAX) |
else if (errindex < LT_ERROR_MAX) |
828 |
{ |
{ |
829 |
/* No error setting the error message! */ |
/* No error setting the error message! */ |
830 |
LT_DLMUTEX_SETERROR (lt_dlerror_strings[errorcount]); |
LT_DLMUTEX_SETERROR (lt_dlerror_strings[errindex]); |
831 |
} |
} |
832 |
else |
else |
833 |
{ |
{ |
834 |
/* No error setting the error message! */ |
/* No error setting the error message! */ |
835 |
LT_DLMUTEX_SETERROR (user_error_strings[errorcount - LT_ERROR_MAX]); |
LT_DLMUTEX_SETERROR (user_error_strings[errindex - LT_ERROR_MAX]); |
836 |
} |
} |
837 |
|
|
838 |
LT_DLMUTEX_UNLOCK (); |
LT_DLMUTEX_UNLOCK (); |
3507 |
lt_dlhandle_next (place) |
lt_dlhandle_next (place) |
3508 |
lt_dlhandle place; |
lt_dlhandle place; |
3509 |
{ |
{ |
3510 |
return place ? place->next : (lt_dlhandle) 0; |
return place ? place->next : handles; |
3511 |
} |
} |
3512 |
|
|
3513 |
int |
int |
3541 |
lt_dlcaller_id |
lt_dlcaller_id |
3542 |
lt_dlcaller_register () |
lt_dlcaller_register () |
3543 |
{ |
{ |
3544 |
static int last_caller_id = -1; |
static lt_dlcaller_id last_caller_id = 0; |
3545 |
int result; |
int result; |
3546 |
|
|
3547 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
3551 |
return result; |
return result; |
3552 |
} |
} |
3553 |
|
|
|
#define N_ELEMENTS(a) (sizeof(a) / sizeof(*(a))) |
|
|
|
|
3554 |
lt_ptr |
lt_ptr |
3555 |
lt_dlcaller_set_data (key, handle, data) |
lt_dlcaller_set_data (key, handle, data) |
3556 |
lt_dlcaller_id key; |
lt_dlcaller_id key; |
3566 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
3567 |
|
|
3568 |
if (handle->caller_data) |
if (handle->caller_data) |
3569 |
n_elements = N_ELEMENTS (handle->caller_data); |
while (handle->caller_data[n_elements].key) |
3570 |
|
++n_elements; |
3571 |
|
|
3572 |
for (i = 0; i < n_elements; ++i) |
for (i = 0; i < n_elements; ++i) |
3573 |
{ |
{ |
3579 |
} |
} |
3580 |
|
|
3581 |
/* Ensure that there is enough room in this handle's caller_data |
/* Ensure that there is enough room in this handle's caller_data |
3582 |
array to accept a new element. */ |
array to accept a new element (and an empty end marker). */ |
3583 |
if (i == n_elements) |
if (i == n_elements) |
3584 |
{ |
{ |
3585 |
lt_caller_data *temp |
lt_caller_data *temp |
3586 |
= LT_DLREALLOC (lt_caller_data, handle->caller_data, 1+ n_elements); |
= LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); |
3587 |
|
|
3588 |
if (!temp) |
if (!temp) |
3589 |
{ |
{ |
3595 |
|
|
3596 |
/* We only need this if we needed to allocate a new caller_data. */ |
/* We only need this if we needed to allocate a new caller_data. */ |
3597 |
handle->caller_data[i].key = key; |
handle->caller_data[i].key = key; |
3598 |
|
handle->caller_data[1+ i].key = 0; |
3599 |
} |
} |
3600 |
|
|
3601 |
handle->caller_data[i].data = data; |
handle->caller_data[i].data = data; |
3612 |
lt_dlhandle handle; |
lt_dlhandle handle; |
3613 |
{ |
{ |
3614 |
lt_ptr result = (lt_ptr) 0; |
lt_ptr result = (lt_ptr) 0; |
|
int n_elements = 0; |
|
3615 |
|
|
3616 |
/* This needs to be locked so that the caller data isn't updated by |
/* This needs to be locked so that the caller data isn't updated by |
3617 |
another thread part way through this function. */ |
another thread part way through this function. */ |
3618 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
3619 |
|
|
|
if (handle->caller_data) |
|
|
n_elements = N_ELEMENTS (handle->caller_data); |
|
|
|
|
3620 |
/* Locate the index of the element with a matching KEY. */ |
/* Locate the index of the element with a matching KEY. */ |
3621 |
{ |
{ |
3622 |
int i; |
int i; |
3623 |
for (i = 0; i < n_elements; ++i) |
for (i = 0; handle->caller_data[i].key; ++i) |
3624 |
{ |
{ |
3625 |
if (handle->caller_data[i].key == key) |
if (handle->caller_data[i].key == key) |
3626 |
{ |
{ |