From: Soo-Hyun Choi Date: Thu, 26 Sep 2013 05:52:30 +0000 (+0900) Subject: Fix a common mistake about errno(3) usage X-Git-Tag: 2.2.1_release~9^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d4205179cd1046a2fc63f089214ee41482d2d52;p=framework%2Fweb%2Fwrt-installer.git Fix a common mistake about errno(3) usage [Issue#] N/A [Problem] errno may have been changed by other system call. [Cause] errno should be preserved. [Solution] Save errno to a local variable [Remarks] ERRNO(3) A common mistake is to do if (somecall() == -1) { printf("somecall() failed\n"); if (errno == ...) { ... } } where errno no longer needs to have the value it had upon return from somecall() (i.e., it may have been changed by the printf(3)). If the value of errno should be preserved across a library call, it must be saved: if (somecall() == -1) { int errsv = errno; printf("somecall() failed\n"); if (errsv == ...) { ... } } Change-Id: Ib407b8a7b1cd13d37c3f182c4c28f059bb1749ea --- diff --git a/src/jobs/widget_install/task_manifest_file.cpp b/src/jobs/widget_install/task_manifest_file.cpp index cb7080d..4e6699b 100644 --- a/src/jobs/widget_install/task_manifest_file.cpp +++ b/src/jobs/widget_install/task_manifest_file.cpp @@ -191,9 +191,11 @@ void TaskManifestFile::stepCreateExecFile() std::string boxSymlink = m_context.locations->getExecFile(); boxSymlink += ".d-box"; + errno = 0; if (symlink(boxExec.c_str(), boxSymlink.c_str()) != 0) { - if (errno) { - _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(errno).c_str()); + int error = errno; + if (error) { + _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str()); } } }