Code cleanup (#251)
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / ni_common.cc
index 52ea3ef..a45043e 100644 (file)
@@ -145,6 +145,17 @@ static bool checkNIExistence(const std::string& path)
 }
 
 #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()
@@ -186,7 +197,7 @@ static uintptr_t getNextBaseAddr()
 }
 
 // Save base address of system ni image to file
-static void updateBaseAddrFile(const std::string &absNIPath, uintptr_t baseAddr)
+static void updateBaseAddrFile(const std::stringabsNIPath, uintptr_t baseAddr)
 {
        uintptr_t niSize = getFileSize(absNIPath);
        if (niSize == 0) {
@@ -206,7 +217,7 @@ static void updateBaseAddrFile(const std::string &absNIPath, uintptr_t baseAddr)
 }
 
 // check if dll is listed in TPA
-static bool isTPADll(const std::string &dllPath)
+static bool isTPADll(const std::stringdllPath)
 {
        std::string absDllPath = getAbsolutePath(dllPath);
 
@@ -380,7 +391,7 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
        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");
        }
 
@@ -491,7 +502,6 @@ void finalizeNICommon()
        __tpa.clear();
 }
 
-
 ni_error_e createNIPlatform(DWORD flags)
 {
        if (createCoreLibNI(flags) != NI_ERROR_NONE) {
@@ -515,7 +525,7 @@ ni_error_e createNIDll(const std::string& dllPath, DWORD flags)
        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) {
@@ -544,14 +554,14 @@ ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags)
                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;
@@ -565,7 +575,7 @@ ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags)
                                                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;
                                                        }
@@ -635,14 +645,14 @@ ni_error_e createNIUnderDirs(const std::string rootPaths[], int count, DWORD fla
 
 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};
 
@@ -656,14 +666,14 @@ ni_error_e createNIDllUnderPkgRoot(const std::string& pkgId, const std::string&
                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;
@@ -675,7 +685,7 @@ ni_error_e createNIDllUnderPkgRoot(const std::string& pkgId, const std::string&
                                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;
                                        }
@@ -757,14 +767,14 @@ void removeNIUnderDirs(const std::string rootPaths[], int count)
 
 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);