From cfe7065ce16511521d68b864398d1da0f0c5130e Mon Sep 17 00:00:00 2001 From: Tilo Eckert Date: Thu, 30 Jun 2016 12:27:43 +0200 Subject: [PATCH] sftp: Do not always set SSH_FXF_READ Comparison ((flags & O_RDONLY) == O_RDONLY) is always true. Also, O_RDWR, O_WRONLY and O_RDONLY are mutually exclusive => no need to check all of them Signed-off-by: Tilo Eckert --- src/sftp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index cad6c005..6ff2a381 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1626,12 +1626,13 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags, attr.permissions = mode; attr.flags = SSH_FILEXFER_ATTR_PERMISSIONS; - if ((flags & O_RDONLY) == O_RDONLY) - sftp_flags |= SSH_FXF_READ; - if ((flags & O_WRONLY) == O_WRONLY) - sftp_flags |= SSH_FXF_WRITE; - if ((flags & O_RDWR) == O_RDWR) + if ((flags & O_RDWR) == O_RDWR) { sftp_flags |= (SSH_FXF_WRITE | SSH_FXF_READ); + } else if ((flags & O_WRONLY) == O_WRONLY) { + sftp_flags |= SSH_FXF_WRITE; + } else { + sftp_flags |= SSH_FXF_READ; + } if ((flags & O_CREAT) == O_CREAT) sftp_flags |= SSH_FXF_CREAT; if ((flags & O_TRUNC) == O_TRUNC)