Fix a common mistake about errno(3) usage
authorSoo-Hyun Choi <sh9.choi@samsung.com>
Thu, 26 Sep 2013 05:52:30 +0000 (14:52 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Fri, 27 Sep 2013 05:31:20 +0000 (05:31 +0000)
commit3d4205179cd1046a2fc63f089214ee41482d2d52
treed607bd09a221647a814154e5d8f30e43e06d20d6
parenta4a1e42831d14555b812c0d8ab3bea41d2fb5426
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
src/jobs/widget_install/task_manifest_file.cpp