return 0;
}
- char command[512] = {0,};
- char fileName[512] = {0,};
+ char* pCommand = null;
+ char* pFileName = null;
+ int fileLength = 0;
+ int commandLength = 0;
long long size = 0;
int ret = 0;
+ FILE* pFile = null;
Tizen::App::App* pApp = Tizen::App::App::GetInstance();
if(pApp == null)
}
String appId(pApp->GetAppId());
- unique_ptr <char> appIdPath(_StringConverter::CopyToCharArrayN(appId));
+ unique_ptr <char[]> appIdPath(_StringConverter::CopyToCharArrayN(appId));
- ret = sprintf(fileName, "/tmp/size_of_directory_%s.tmp", appIdPath.get());
- if(ret < 1)
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to write file path.");
- return 0;
- }
+ fileLength = strlen(appIdPath.get()) + 29;
+ pFileName = (char*)malloc(fileLength);
+ SysTryCatch(NID_SYS, pFileName, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "It is not enough memory.");
- ret = sprintf(command, "rm -rf %s", fileName);
- if(ret < 1)
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to write remove command.");
- return 0;
- }
+ ret = sprintf(pFileName, "/tmp/size_of_directory_%s.tmp", appIdPath.get());
+ SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write file path.");
+
+ commandLength = strlen(pFileName) + 8;
+ pCommand = (char*) malloc(commandLength);
+ SysTryCatch(NID_SYS, pCommand, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "It is not enough memory.");
- ret = system(command);
+ ret = sprintf(pCommand, "rm -rf %s", pFileName);
+ SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write remove pCommand.");
+ ret = system(pCommand);
if(ret == -1)
{
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute pCommand[%s].", pCommand);
}
+ free(pCommand);
+ pCommand = null;
- ret = sprintf(command, "du -skb -P %s >> %s", path, fileName);
- if(ret < 1)
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to write du command.");
- return 0;
- }
+ commandLength = strlen(pFileName) + strlen(path) + 16;
+ pCommand = (char*)malloc(commandLength);
+ SysTryCatch(NID_SYS, pCommand, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "It is not enough memory.");
- ret = system(command);
- if(ret == -1)
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
- return 0;
- }
+ ret = sprintf(pCommand, "du -skb -P %s >> %s", path, pFileName);
+ SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write du pCommand.");
- FILE* pFile = null;
- pFile = fopen(fileName, "r");
- if(pFile == null)
- {
- return 0;
- }
+ ret = system(pCommand);
+ SysTryCatch(NID_SYS, ret != -1, E_SYSTEM, E_SYSTEM, "It is failed to execute pCommand[%s].", pCommand);
+
+ pFile = fopen(pFileName, "r");
+ SysTryCatch(NID_SYS, pFile != null, E_SYSTEM, E_SYSTEM, "It is failed to read file [%s].", pFileName);
ret = fscanf(pFile, "%lld", &size);
- if(ret < 1)
- {
- if(pFile != null)
- {
- fclose(pFile);
- }
+ SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to read file [%s].", pFileName);
- return 0;
- }
+ ret = sprintf(pCommand, "rm -rf %s", pFileName);
+ SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write remove pCommand.");
+
+ ret = system(pCommand);
+ SysTryCatch(NID_SYS, ret != -1, E_SYSTEM, E_SYSTEM, "It is failed to execute pCommand[%s].", pCommand);
- if(pFile != null)
+CATCH:
+ if (pFileName)
{
- fclose(pFile);
+ free(pFileName);
}
-
- ret = sprintf(command, "rm -rf %s", fileName);
- if(ret < 1)
+ if (pCommand)
{
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to write remove command.");
- return 0;
+ free(pCommand);
}
-
- ret = system(command);
- if(ret == -1)
+ if (pFile)
{
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
+ fclose(pFile);
}
-
-
return size;
}