aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2013-06-28 18:09:47 +0300
committerLasse Collin <lasse.collin@tukaani.org>2013-06-28 22:04:36 +0300
commit78c2f8db902195468b8249c432252a6b281db836 (patch)
tree6c28afb0af680d1e224b15917fba6bbc55b276c2
parentxz: Fix use of wrong variable in a fcntl() call. (diff)
downloadxz-78c2f8db902195468b8249c432252a6b281db836.tar.xz
xz: Fix error detection of fcntl(fd, F_SETFL, flags) calls.
POSIX says that fcntl(fd, F_SETFL, flags) returns -1 on error and "other than -1" on success. This is how it is documented e.g. on OpenBSD too. On Linux, success with F_SETFL is always 0 (at least accorinding to fcntl(2) from man-pages 3.51).
-rw-r--r--src/xz/file_io.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/xz/file_io.c b/src/xz/file_io.c
index 4fd6855d..f601c564 100644
--- a/src/xz/file_io.c
+++ b/src/xz/file_io.c
@@ -442,7 +442,7 @@ io_open_src_real(file_pair *pair)
flags &= ~O_NONBLOCK;
- if (fcntl(pair->src_fd, F_SETFL, flags))
+ if (fcntl(pair->src_fd, F_SETFL, flags) == -1)
goto error_msg;
}
#endif
@@ -658,7 +658,8 @@ io_open_dest_real(file_pair *pair)
return false;
if (fcntl(STDOUT_FILENO, F_SETFL,
- stdout_flags & ~O_APPEND))
+ stdout_flags & ~O_APPEND)
+ == -1)
return false;
// Disabling O_APPEND succeeded. Mark
@@ -708,10 +709,9 @@ io_close_dest(file_pair *pair, bool success)
if (restore_stdout_flags) {
assert(pair->dest_fd == STDOUT_FILENO);
- const int fail = fcntl(STDOUT_FILENO, F_SETFL, stdout_flags);
restore_stdout_flags = false;
- if (fail) {
+ if (fcntl(STDOUT_FILENO, F_SETFL, stdout_flags) == -1) {
message_error(_("Error restoring the O_APPEND flag "
"to standard output: %s"),
strerror(errno));