From cf87dfa3f44172635b9d071c83cd2fcd2479c668 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 2 Jul 2009 00:52:28 +0000 Subject: libglusterfsclient: Use O_ACCMODE for access mode checks Ref: http://www.gnu.org/s/libc/manual/html_node/Access-Modes.html Signed-off-by: Anand V. Avati --- libglusterfsclient/src/libglusterfsclient.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libglusterfsclient/src') diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 576fef7f1..7246c91cc 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -2403,7 +2403,8 @@ libgf_client_opendir (libglusterfs_client_ctx_t *ctx, int32_t op_ret = -1; libgf_client_local_t *local = NULL; - if ((fd->flags & O_WRONLY) || (fd->flags & O_RDWR)) { + if (((fd->flags & O_ACCMODE) == O_WRONLY) + || ((fd->flags & O_ACCMODE) == O_RDWR)) { errno = EISDIR; goto out; } @@ -2521,7 +2522,8 @@ op_over: } } - if ((flags & O_TRUNC) && ((flags & O_RDWR) || (flags & O_WRONLY))) { + if ((flags & O_TRUNC) && (((flags & O_ACCMODE) == O_RDWR) + || ((flags & O_ACCMODE) == O_WRONLY))) { inode_ctx = libgf_get_inode_ctx (fd->inode); if (S_ISREG (inode_ctx->stbuf.st_mode)) { inode_ctx->stbuf.st_size = 0; @@ -5150,7 +5152,8 @@ libgf_client_ftruncate (libglusterfs_client_ctx_t *ctx, fd_t *fd, int op_ret = -1; libglusterfs_client_fd_ctx_t *fdctx = NULL; - if (!(fd->flags & O_RDWR) && (!(fd->flags & O_WRONLY))) { + if ((!(fd->flags & O_ACCMODE) == O_RDWR) + && (!((fd->flags & O_ACCMODE) == O_WRONLY))) { errno = EBADF; goto out; } -- cgit