[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
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());
}
}
}