TimeZone
_LocaleManagerImpl::GetSystemTimeZone(void)
{
- char pTZPath[256] = {0,};
+ char* pTZPath = null;
char* pTZID = null;
- bool isDeleted = false;
- ssize_t nLen = readlink("/opt/etc/localtime", pTZPath, sizeof(pTZPath)-1);
+ TimeZone timeZone;
+ DateTime utcTime;
+ struct tm gmTime;
+ struct tm* pGmTime = null;
+ time_t currTime = time(null);
+ result r = E_SUCCESS;
+ ssize_t nLen = -1;
+
+ pTZPath = (char*)malloc(sizeof(char) * 256);
+ SysTryCatch(NID_LCL, pTZPath, , E_OUT_OF_MEMORY, "It is not enough memory.");
+
+ nLen = readlink("/opt/etc/localtime", pTZPath, 255);
if (nLen > 20)
{
pTZPath[nLen] = '\0';
- pTZID = &pTZPath[20];
+ pTZID = pTZPath + 20;
}
else
{
pTZID = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
- SysTryReturn(NID_LCL, pTZID, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone.");
- isDeleted = true;
+ SysTryCatch(NID_LCL, pTZID, , E_SYSTEM, "It is failed to get System Time Zone.");
+ free(pTZPath);
+ pTZPath = pTZID;
}
- TimeZone timeZone;
- DateTime utcTime;
- struct tm gmTime;
- struct tm* pGmTime = null;
- time_t currTime = time(null);
-
pGmTime = gmtime_r(&currTime, &gmTime);
- SysTryReturn(NID_LCL, pGmTime, TimeZone(-1, ""), E_SYSTEM, "It is failed to convert the time value to UTC time.");
+ SysTryCatch(NID_LCL, pGmTime, , E_SYSTEM, "It is failed to convert the time value to UTC time.");
utcTime.SetValue(gmTime.tm_year + 1900, gmTime.tm_mon + 1, gmTime.tm_mday, gmTime.tm_hour, gmTime.tm_min, gmTime.tm_sec);
- result r = Tizen::Locales::TimeZone::GetTimeZone(String(pTZID), utcTime, timeZone);
- if (isDeleted)
+ r = Tizen::Locales::TimeZone::GetTimeZone(String(pTZID), utcTime, timeZone);
+ SysTryCatch(NID_LCL, r == E_SUCCESS, , r, "[%s] error occurs.", GetErrorMessage(r));
+ free(pTZPath);
+ return timeZone;
+
+CATCH:
+ if (pTZPath)
{
- delete pTZID;
+ free(pTZPath);
}
- SysTryReturn(NID_LCL, r == E_SUCCESS, TimeZone(-1, ""), r, "[%s] error occurs.", GetErrorMessage(r));
- return timeZone;
+ return TimeZone(-1, "");
}
result