static bool CC KDlsetTrySymbol ( void *item, void *data ) { KSymAddr *sym; KDlsetTrySymData *pb = data; pb -> rc = KDylibSymbol ( item, & sym, pb -> name ); if ( pb -> rc == 0 ) { /* simple case */ if ( pb -> test == NULL ) { pb -> sym = sym; return true; } /* apply filter function */ if ( ( * pb -> test ) ( sym, pb -> data ) ) { KSymAddrRelease ( pb -> sym ); pb -> sym = sym; return pb -> first; } KSymAddrRelease ( sym ); } return false; }
static rc_t KNSManagerLoadLib( struct KNSManager *self ) { KDyld *dl; /* make a dynamic-library loader */ rc_t rc = KDyldMake ( &dl ); if ( rc == 0 ) { /* load the curl-library */ rc = KDyldLoadLib( dl, &lib_curl_handle, LPFX "curl" SHLX ); if ( rc == 0 ) { KSymAddr *sym; /* resolve symbols */ /* curl_easy_init() */ rc = KDylibSymbol( lib_curl_handle, &sym, "curl_easy_init" ); if ( rc == 0 ) { KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_easy_init_fkt) ); KSymAddrRelease( sym ); } /* curl_easy_cleanup() */ if ( rc == 0 ) { rc = KDylibSymbol( lib_curl_handle, &sym, "curl_easy_cleanup" ); KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_easy_cleanup_fkt) ); KSymAddrRelease( sym ); } /* curl_easy_setopt() */ if ( rc == 0 ) { rc = KDylibSymbol( lib_curl_handle, &sym, "curl_easy_setopt" ); KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_easy_setopt_fkt) ); KSymAddrRelease( sym ); } /* curl_easy_perform() */ if ( rc == 0 ) { rc = KDylibSymbol( lib_curl_handle, &sym, "curl_easy_perform" ); KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_easy_perform_fkt) ); KSymAddrRelease( sym ); } /* curl_easy_getinfo() */ if ( rc == 0 ) { rc = KDylibSymbol( lib_curl_handle, &sym, "curl_easy_getinfo" ); KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_easy_getinfo_fkt) ); KSymAddrRelease( sym ); } /* curl_slist_append() */ if ( rc == 0 ) { rc = KDylibSymbol( lib_curl_handle, &sym, "curl_slist_append" ); KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_slist_append_fkt) ); KSymAddrRelease( sym ); } /* curl_version() */ if ( rc == 0 ) { rc = KDylibSymbol( lib_curl_handle, &sym, "curl_version" ); KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_version_fkt) ); KSymAddrRelease( sym ); } /* curl_slist_free_all() */ if ( rc == 0 ) { rc = KDylibSymbol( lib_curl_handle, &sym, "curl_slist_free_all" ); KSymAddrAsFunc( sym, ( fptr_t* ) &(self->curl_slist_free_all_fkt) ); KSymAddrRelease( sym ); } /* bail on error */ if ( rc != 0 ) { KDylibRelease ( lib_curl_handle ); lib_curl_handle = NULL; self->curl_easy_init_fkt = NULL; self->curl_easy_cleanup_fkt = NULL; self->curl_easy_setopt_fkt = NULL; self->curl_easy_perform_fkt = NULL; self->curl_slist_append_fkt = NULL; self->curl_version_fkt = NULL; self->curl_easy_getinfo_fkt = NULL; } } KDyldRelease ( dl ); } return rc; }