/* load library */ static void testld_load_library ( KDyld *dl, KDlset *libs, const char *libname ) { KDylib *lib; rc_t rc = KDyldLoadLib ( dl, & lib, libname ); if ( rc != 0 ) { PLOGERR ( klogErr, ( klogErr, rc, "failed to load library '$(name)'", "name=%s", libname )); } else { printf ( "loaded library '%s'\n", libname); rc = KDlsetAddLib ( libs, lib ); if ( rc != 0 ) { PLOGERR ( klogInt, ( klogInt, rc, "failed to retain library '$(name)'", "name=%s", libname )); } KDylibRelease ( lib ); } }
/* MakeSet * load a dynamic library * * "set" [ OUT ] - return parameter for lib set */ LIB_EXPORT rc_t CC KDyldMakeSet ( const KDyld *self, KDlset **setp ) { rc_t rc = 0; if ( setp == NULL ) rc = RC ( rcFS, rcDylib, rcConstructing, rcParam, rcNull ); else { if ( self == NULL ) rc = RC ( rcFS, rcDylib, rcConstructing, rcSelf, rcNull ); else { KDlset *set = malloc ( sizeof * set ); if ( set == NULL ) rc = RC ( rcFS, rcDylib, rcConstructing, rcMemory, rcExhausted ); else { set -> dl = KDyldAttach ( self ); VectorInit ( & set -> name, 0, 16 ); VectorInit ( & set -> ord, 0, 16 ); KRefcountInit ( & set -> refcount, 1, "KDlset", "make", "dlset" ); #if ! ALWAYS_ADD_EXE { KDylib *jni; const char* libname = "vdb_jni.dll"; rc = KDyldLoadLib ( ( KDyld* ) self, & jni, libname ); if ( rc == 0 ) { rc = KDlsetAddLib ( set, jni ); KDylibRelease ( jni ); } /*if (rc == 0)*/ /* if JNI code is not there, C tools should not suffer */ { * setp = set; return 0; } } #else { KDylib *exe; rc = KDyldLoadLib ( ( KDyld* ) self, & exe, NULL ); if ( rc == 0 ) { rc = KDlsetAddLib ( set, exe ); KDylibRelease ( exe ); if ( rc == 0 ) { * setp = set; return 0; } } } KDlsetRelease ( set ); #endif } } * setp = NULL; } return rc; }