ruby-changes:66961
From: S.H <ko1@a...>
Date: Thu, 29 Jul 2021 12:51:30 +0900 (JST)
Subject: [ruby-changes:66961] 64adeeadaa (master): Add RBOOL macro and use it
https://git.ruby-lang.org/ruby.git/commit/?id=64adeeadaa From 64adeeadaa8d7fe210d0605eb6c9b0b1dcf49746 Mon Sep 17 00:00:00 2001 From: "S.H" <gamelinks007@g...> Date: Thu, 29 Jul 2021 12:51:10 +0900 Subject: Add RBOOL macro and use it --- file.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/file.c b/file.c index 649dfcc..0afee42 100644 --- a/file.c +++ b/file.c @@ -171,6 +171,8 @@ int flock(int, int); https://github.com/ruby/ruby/blob/trunk/file.c#L171 #include "ruby/thread.h" #include "ruby/util.h" +#define RBOOL(v) ((v) ? Qtrue : Qfalse) + VALUE rb_cFile; VALUE rb_mFileTest; VALUE rb_cStat; @@ -1830,8 +1832,7 @@ rb_file_exists_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1832 static VALUE rb_file_readable_p(VALUE obj, VALUE fname) { - if (rb_eaccess(fname, R_OK) < 0) return Qfalse; - return Qtrue; + return RBOOL(rb_eaccess(fname, R_OK) >= 0); } /* @@ -1848,8 +1849,7 @@ rb_file_readable_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1849 static VALUE rb_file_readable_real_p(VALUE obj, VALUE fname) { - if (rb_access(fname, R_OK) < 0) return Qfalse; - return Qtrue; + return RBOOL(rb_access(fname, R_OK) >= 0); } #ifndef S_IRUGO @@ -1904,8 +1904,7 @@ rb_file_world_readable_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1904 static VALUE rb_file_writable_p(VALUE obj, VALUE fname) { - if (rb_eaccess(fname, W_OK) < 0) return Qfalse; - return Qtrue; + return RBOOL(rb_eaccess(fname, W_OK) >= 0); } /* @@ -1922,8 +1921,7 @@ rb_file_writable_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1921 static VALUE rb_file_writable_real_p(VALUE obj, VALUE fname) { - if (rb_access(fname, W_OK) < 0) return Qfalse; - return Qtrue; + return RBOOL(rb_access(fname, W_OK) >= 0); } /* @@ -1974,8 +1972,7 @@ rb_file_world_writable_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1972 static VALUE rb_file_executable_p(VALUE obj, VALUE fname) { - if (rb_eaccess(fname, X_OK) < 0) return Qfalse; - return Qtrue; + return RBOOL(rb_eaccess(fname, X_OK) >= 0); } /* @@ -1996,8 +1993,7 @@ rb_file_executable_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1993 static VALUE rb_file_executable_real_p(VALUE obj, VALUE fname) { - if (rb_access(fname, X_OK) < 0) return Qfalse; - return Qtrue; + return RBOOL(rb_access(fname, X_OK) >= 0); } #ifndef S_ISREG -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/