1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
normal 2017-11-24 04:49:05 +00:00
parent ea576241b0
commit 8fb87e43c6

19
file.c
View file

@ -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;
}