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:
parent
ea576241b0
commit
8fb87e43c6
19
file.c
19
file.c
@ -1414,6 +1414,13 @@ eaccess(const char *path, int mode)
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
* Document-class: FileTest
|
||||||
@ -1658,9 +1665,7 @@ rb_file_exists_p(VALUE obj, VALUE fname)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_file_readable_p(VALUE obj, VALUE fname)
|
rb_file_readable_p(VALUE obj, VALUE fname)
|
||||||
{
|
{
|
||||||
FilePathValue(fname);
|
if (rb_eaccess(fname, R_OK) < 0) return Qfalse;
|
||||||
fname = rb_str_encode_ospath(fname);
|
|
||||||
if (eaccess(StringValueCStr(fname), R_OK) < 0) return Qfalse;
|
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1730,9 +1735,7 @@ rb_file_world_readable_p(VALUE obj, VALUE fname)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_file_writable_p(VALUE obj, VALUE fname)
|
rb_file_writable_p(VALUE obj, VALUE fname)
|
||||||
{
|
{
|
||||||
FilePathValue(fname);
|
if (rb_eaccess(fname, W_OK) < 0) return Qfalse;
|
||||||
fname = rb_str_encode_ospath(fname);
|
|
||||||
if (eaccess(StringValueCStr(fname), W_OK) < 0) return Qfalse;
|
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1794,9 +1797,7 @@ rb_file_world_writable_p(VALUE obj, VALUE fname)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_file_executable_p(VALUE obj, VALUE fname)
|
rb_file_executable_p(VALUE obj, VALUE fname)
|
||||||
{
|
{
|
||||||
FilePathValue(fname);
|
if (rb_eaccess(fname, X_OK) < 0) return Qfalse;
|
||||||
fname = rb_str_encode_ospath(fname);
|
|
||||||
if (eaccess(StringValueCStr(fname), X_OK) < 0) return Qfalse;
|
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user