}
#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
+static uintptr_t getFileSize(const std::string& path)
+{
+ struct stat sb;
+
+ if (stat(path.c_str(), &sb) == 0) {
+ return sb.st_size;
+ }
+
+ return 0;
+}
+
// Get next base address to be used for system ni image from file
// __SYSTEM_BASE_FILE should be checked for existance before calling this function
static uintptr_t getNextBaseAddrFromFile()
}
// Save base address of system ni image to file
-static void updateBaseAddrFile(const std::string &absNIPath, uintptr_t baseAddr)
+static void updateBaseAddrFile(const std::string& absNIPath, uintptr_t baseAddr)
{
uintptr_t niSize = getFileSize(absNIPath);
if (niSize == 0) {
}
// check if dll is listed in TPA
-static bool isTPADll(const std::string &dllPath)
+static bool isTPADll(const std::string& dllPath)
{
std::string absDllPath = getAbsolutePath(dllPath);
if (createTACPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) {
fprintf(stderr, "Failed to generate symbolic link file [%s]\n", pkgId);
return -1;
- }else {
+ } else {
fprintf(stdout, "Complete make symbolic link file to tac\n");
}
__tpa.clear();
}
-
ni_error_e createNIPlatform(DWORD flags)
{
if (createCoreLibNI(flags) != NI_ERROR_NONE) {
return crossgen(dllPath, std::string(), flags);
}
-void createNIUnderTAC(std::vector<std::string> nugets, DWORD flags)
+static void createNIUnderTAC(const std::vector<std::string>& nugets, DWORD flags)
{
std::string appPaths;
for (auto& nuget : nugets) {
return NI_ERROR_CORE_NI_FILE;
}
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
std::string paths = binDir + ":" + libDir + ":" + tacDir;
std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
if (!bf::exists(originNIPath)) {
flags |= NI_FLAGS_APPNI;
- if(crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
+ if (crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
return NI_ERROR_UNKNOWN;
}
ni_error_e createNIUnderPkgRoot(const std::string& pkgId, DWORD flags)
{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string paths[] = {binDir, libDir, tacDir};
return NI_ERROR_CORE_NI_FILE;
}
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
std::string paths = binDir + ":" + libDir + ":" + tacDir;
std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
if (!bf::exists(originNIPath)) {
flags |= NI_FLAGS_APPNI;
- if(crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
+ if (crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
return NI_ERROR_UNKNOWN;
}
ni_error_e removeNIUnderPkgRoot(const std::string& pkgId)
{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string paths[] = {binDir, libDir};
removeNIUnderDirs(paths, 2);