[前][次][番号順一覧][スレッド一覧]

ruby-changes:48779

From: normal <ko1@a...>
Date: Fri, 24 Nov 2017 13:49:10 +0900 (JST)
Subject: [ruby-changes:48779] normal:r60895 (trunk): file.c: simplify eaccess(3) callers

normal	2017-11-24 13:49:05 +0900 (Fri, 24 Nov 2017)

  New Revision: 60895

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60895

  Log:
    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

  Modified files:
    trunk/file.c
Index: file.c
===================================================================
--- file.c	(revision 60894)
+++ file.c	(revision 60895)
@@ -1414,6 +1414,13 @@ eaccess(const char *path, int mode) https://github.com/ruby/ruby/blob/trunk/file.c#L1414
 }
 #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) https://github.com/ruby/ruby/blob/trunk/file.c#L1665
 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, VALU https://github.com/ruby/ruby/blob/trunk/file.c#L1735
 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, VALU https://github.com/ruby/ruby/blob/trunk/file.c#L1797
 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;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]