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