diff options
author | Andi Shyti <andi.shyti@nokia.com> | 2013-05-28 00:43:03 +0200 |
---|---|---|
committer | Andi Shyti <andi.shyti@nokia.com> | 2013-05-28 00:43:03 +0200 |
commit | c7f133ca984946c74cffbcab2c95be90f615bf41 (patch) | |
tree | b83208ac9ba7dc68e1b52506272d45807b1fe9de /drivers/misc/apds990x_proxy.c | |
parent | a15837abae685a297cfb6f029341291708e96d66 (diff) |
apds990x_proxy: fix errno usage.
This patch fixes one of the most common errors about errno usage:
if (somecall() == -1) {
printf("somecall() failed\n");
if (errno == ...) { ... }
}
printf may change the value of errno, so that the errno value in
the if statement is not anymore referring to 'somecall()'
function.
The correct usage should be:
if (somecall() == -1) {
int errsv = errno;
printf("somecall() failed\n");
if (errsv == ...) { ... }
}
Signed-off-by: Andi Shyti <andi.shyti@nokia.com>
Diffstat (limited to 'drivers/misc/apds990x_proxy.c')
-rw-r--r-- | drivers/misc/apds990x_proxy.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/misc/apds990x_proxy.c b/drivers/misc/apds990x_proxy.c index f5e701c..ba6ea3d 100644 --- a/drivers/misc/apds990x_proxy.c +++ b/drivers/misc/apds990x_proxy.c @@ -47,25 +47,30 @@ int write_file(char *fname, const char *val) { int fd; ssize_t ret; + int retval = 0; fd = open(fname, O_WRONLY); if (fd < 0) { + retval = errno; fprintf(stderr, "%s: %s\n", fname, strerror(errno)); - return errno; + return retval; } ret = write(fd, val, 1); if (ret != 1) { + retval = errno; fprintf(stderr, "%s: %s\n", fname, strerror(errno)); close(fd); - return errno; + return retval; } fd = close(fd); - if (fd < 0) + if (fd < 0) { + retval = errno; fprintf(stderr, "%s: %s\n", fname, strerror(errno)); + } - return errno; + return retval; } int read_proxy(void) |