From 8fb87e43c6f5f176fadc74fe51b98d0ddc0f6d61 Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 24 Nov 2017 04:49:05 +0000 Subject: file.c: simplify eaccess(3) callers This will make future work to release GVL here simpler. * file.c (rb_eaccess): new function (rb_file_readable_p): use rb_eaccess (rb_file_writable_p): ditto (rb_file_executable_p): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index 982a30c4a3..884ec8518e 100644 --- a/file.c +++ b/file.c @@ -1414,6 +1414,13 @@ eaccess(const char *path, int mode) } #endif +static int +rb_eaccess(VALUE fname, int mode) +{ + FilePathValue(fname); + fname = rb_str_encode_ospath(fname); + return eaccess(StringValueCStr(fname), mode); +} /* * Document-class: FileTest @@ -1658,9 +1665,7 @@ rb_file_exists_p(VALUE obj, VALUE fname) static VALUE rb_file_readable_p(VALUE obj, VALUE fname) { - FilePathValue(fname); - fname = rb_str_encode_ospath(fname); - if (eaccess(StringValueCStr(fname), R_OK) < 0) return Qfalse; + if (rb_eaccess(fname, R_OK) < 0) return Qfalse; return Qtrue; } @@ -1730,9 +1735,7 @@ rb_file_world_readable_p(VALUE obj, VALUE fname) static VALUE rb_file_writable_p(VALUE obj, VALUE fname) { - FilePathValue(fname); - fname = rb_str_encode_ospath(fname); - if (eaccess(StringValueCStr(fname), W_OK) < 0) return Qfalse; + if (rb_eaccess(fname, W_OK) < 0) return Qfalse; return Qtrue; } @@ -1794,9 +1797,7 @@ rb_file_world_writable_p(VALUE obj, VALUE fname) static VALUE rb_file_executable_p(VALUE obj, VALUE fname) { - FilePathValue(fname); - fname = rb_str_encode_ospath(fname); - if (eaccess(StringValueCStr(fname), X_OK) < 0) return Qfalse; + if (rb_eaccess(fname, X_OK) < 0) return Qfalse; return Qtrue; } -- cgit v1.2.3