bool Runtime::checkAndLoadLibrary(const std::string& libraryPath, const std::string& requestedBindingIdentifier, bool keepLibrary) { void* sharedLibraryHandle = NULL; MiddlewareInfo* foundMiddlewareInfo; if (!tryLoadLibrary(libraryPath, &sharedLibraryHandle, &foundMiddlewareInfo)) { return false; } if (foundMiddlewareInfo->middlewareName_ != requestedBindingIdentifier) { //If library was linked at compile time (and therefore an appropriate runtime loader is registered), //the library must not be closed! auto foundRegisteredRuntimeLoader = registeredRuntimeLoadFunctions_->find(foundMiddlewareInfo->middlewareName_); if (foundRegisteredRuntimeLoader == registeredRuntimeLoadFunctions_->end()) { dlclose(sharedLibraryHandle); } return false; } if (!keepLibrary) { dlclose(sharedLibraryHandle); } else { //Extend visibility to make symbols available to all other libraries that are loaded afterwards, //e.g. libraries containing generated binding specific code. sharedLibraryHandle = dlopen(libraryPath.c_str(), RTLD_NOW | RTLD_GLOBAL); if (!sharedLibraryHandle) { return false; } registeredRuntimeLoadFunctions_->insert( {foundMiddlewareInfo->middlewareName_, foundMiddlewareInfo->getInstance_} ); } return true; }
HI_S32 LoadSensorLibrary(const char *libsns_name) { char path[250]; sprintf(path, "%s", libsns_name); if (tryLoadLibrary(path) != HI_SUCCESS) { sprintf(path, "./%s", libsns_name); if (tryLoadLibrary(path) != HI_SUCCESS) { sprintf(path, "/usr/lib/%s", libsns_name); if (tryLoadLibrary(path) != HI_SUCCESS) { return HI_FAILURE; } } } sensor_register_callback_fn = dlsym(libsns_so, "sensor_register_callback"); sensor_unregister_callback_fn = dlsym(libsns_so, "sensor_unregister_callback"); return HI_SUCCESS; }
bool Runtime::checkAndLoadDefaultLibrary(std::string& foundBindingIdentifier, const std::string& libraryPath) { void* sharedLibraryHandle = NULL; MiddlewareInfo* foundMiddlewareInfo; if (!tryLoadLibrary(libraryPath, &sharedLibraryHandle, &foundMiddlewareInfo)) { return false; } //Extend visibility to make symbols available to all other linked libraries, //e.g. libraries containing generated binding specific code sharedLibraryHandle = dlopen(libraryPath.c_str(), RTLD_NOW | RTLD_GLOBAL); if (!sharedLibraryHandle) { return false; } registeredRuntimeLoadFunctions_->insert( {foundMiddlewareInfo->middlewareName_, foundMiddlewareInfo->getInstance_} ); foundBindingIdentifier = foundMiddlewareInfo->middlewareName_; return true; }
/* * That is a method which gets called from check_wrapper * */ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const char* const argv[]) { Settings& settings = cppcheck.settings(); _settings = &settings; bool std = tryLoadLibrary(settings.library, argv[0], "std.cfg"); bool posix = true; if (settings.standards.posix) posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg"); bool windows = true; if (settings.isWindowsPlatform()) windows = tryLoadLibrary(settings.library, argv[0], "windows.cfg"); if (!std || !posix || !windows) { const std::list<ErrorLogger::ErrorMessage::FileLocation> callstack; const std::string msg("Failed to load " + std::string(!std ? "std.cfg" : !posix ? "posix.cfg" : "windows.cfg") + ". Your Cppcheck installation is broken, please re-install."); #ifdef CFGDIR const std::string details("The Cppcheck binary was compiled with CFGDIR set to \"" + std::string(CFGDIR) + "\" and will therefore search for " "std.cfg in that path."); #else const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(argv[0])) + "cfg"); const std::string details("The Cppcheck binary was compiled without CFGDIR set. Either the " "std.cfg should be available in " + cfgfolder + " or the CFGDIR " "should be configured."); #endif ErrorLogger::ErrorMessage errmsg(callstack, Severity::information, msg+" "+details, "failedToLoadCfg", false); reportErr(errmsg); return EXIT_FAILURE; } if (settings.reportProgress) time1 = std::time(0); if (settings._xml) { reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings._xml_version)); } unsigned int returnValue = 0; if (settings._jobs == 1) { // Single process settings.jointSuppressionReport = true; std::size_t totalfilesize = 0; for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { totalfilesize += i->second; } std::size_t processedsize = 0; unsigned int c = 0; for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { if (!_settings->library.markupFile(i->first) || !_settings->library.processMarkupAfterCode(i->first)) { returnValue += cppcheck.check(i->first); processedsize += i->second; if (!settings.quiet) reportStatus(c + 1, _files.size(), processedsize, totalfilesize); c++; } } // second loop to parse all markup files which may not work until all // c/cpp files have been parsed and checked for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { if (_settings->library.markupFile(i->first) && _settings->library.processMarkupAfterCode(i->first)) { returnValue += cppcheck.check(i->first); processedsize += i->second; if (!settings.quiet) reportStatus(c + 1, _files.size(), processedsize, totalfilesize); c++; } } cppcheck.analyseWholeProgram(); } else if (!ThreadExecutor::isEnabled()) { std::cout << "No thread support yet implemented for this platform." << std::endl; } else { // Multiple processes ThreadExecutor executor(_files, settings, *this); returnValue = executor.check(); } if (settings.isEnabled("information") || settings.checkConfiguration) { const bool enableUnusedFunctionCheck = cppcheck.unusedFunctionCheckIsEnabled(); if (settings.jointSuppressionReport) { for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { reportUnmatchedSuppressions(settings.nomsg.getUnmatchedLocalSuppressions(i->first, enableUnusedFunctionCheck)); } } reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(enableUnusedFunctionCheck)); } if (!settings.checkConfiguration) { cppcheck.tooManyConfigsError("",0U); if (settings.isEnabled("missingInclude") && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) { const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack; ErrorLogger::ErrorMessage msg(callStack, Severity::information, "Cppcheck cannot find all the include files (use --check-config for details)\n" "Cppcheck cannot find all the include files. Cppcheck can check the code without the " "include files found. But the results will probably be more accurate if all the include " "files are found. Please check your project's include directories and add all of them " "as include directories for Cppcheck. To see what files Cppcheck cannot find use " "--check-config.", Preprocessor::missingIncludeFlag ? "missingInclude" : "missingIncludeSystem", false); reportInfo(msg); } } if (settings._xml) { reportErr(ErrorLogger::ErrorMessage::getXMLFooter(settings._xml_version)); } _settings = 0; if (returnValue) return settings._exitCode; else return 0; }
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL_nCreate(JNIEnv *env, jclass clazz, jstring oalPath) { tryLoadLibrary(env, oalPath); }
/** * Tries to locate and load VBoxCAPI.so/dylib/dll, resolving all the related * function pointers. * * @returns 0 on success, -1 on failure. * * @remark This should be considered moved into a separate glue library since * its its going to be pretty much the same for any user of VBoxCAPI * and it will just cause trouble to have duplicate versions of this * source code all around the place. */ int VBoxCGlueInit(void) { const char *pszHome; memset(g_szVBoxErrMsg, 0, sizeof(g_szVBoxErrMsg)); /* * If the user specifies the location, try only that. */ pszHome = getenv("VBOX_APP_HOME"); if (pszHome) return tryLoadLibrary(pszHome, 0); /* * Try the known standard locations. */ #if defined(__gnu__linux__) || defined(__linux__) if (tryLoadLibrary("/opt/VirtualBox", 1) == 0) return 0; if (tryLoadLibrary("/usr/lib/virtualbox", 1) == 0) return 0; #elif defined(__sun__) if (tryLoadLibrary("/opt/VirtualBox/amd64", 1) == 0) return 0; if (tryLoadLibrary("/opt/VirtualBox/i386", 1) == 0) return 0; #elif defined(__APPLE__) if (tryLoadLibrary("/Applications/VirtualBox.app/Contents/MacOS", 1) == 0) return 0; #elif defined(__FreeBSD__) if (tryLoadLibrary("/usr/local/lib/virtualbox", 1) == 0) return 0; #elif defined(__OS2__) if (tryLoadLibrary("C:/Apps/VirtualBox", 1) == 0) return 0; #elif defined(WIN32) pszHome = getenv("ProgramFiles"); if (pszHome) { char szPath[4096]; size_t cb = sizeof(szPath); char *tmp = szPath; strncpy(tmp, pszHome, cb); tmp[cb - 1] = '\0'; cb -= strlen(tmp); tmp += strlen(tmp); strncpy(tmp, "/Oracle/VirtualBox", cb); tmp[cb - 1] = '\0'; if (tryLoadLibrary(szPath, 1) == 0) return 0; } if (tryLoadLibrary("C:/Program Files/Oracle/VirtualBox", 1) == 0) return 0; #else # error "port me" #endif /* * Finally try the dynamic linker search path. */ if (tryLoadLibrary(NULL, 1) == 0) return 0; /* No luck, return failure. */ return -1; }