From 079741af1bbff0e5c02aa9b2ad04732517ef4bac Mon Sep 17 00:00:00 2001 From: yugui Date: Wed, 4 Mar 2009 09:19:31 +0000 Subject: merges r22655,r22658,r22660 and r22661 from trunk into ruby_1_9_1. -- * file.c (file_load_ok): checks if regular file, except for the platform disallows to open directories, e.g. cygwin. [ruby-dev:38097], [Bug #1221] -- * file.c (file_load_ok): cygwin allows to open directories. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@22747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index e46d25d122..642ea82499 100644 --- a/file.c +++ b/file.c @@ -107,7 +107,6 @@ rb_get_path_check(VALUE obj, int check) tmp = rb_check_string_type(obj); if (!NIL_P(tmp)) goto exit; - CONST_ID(to_path, "to_path"); if (rb_respond_to(obj, to_path)) { tmp = rb_funcall(obj, to_path, 0, 0); @@ -294,7 +293,6 @@ rb_stat_dev_minor(VALUE self) #endif } - /* * call-seq: * stat.ino => fixnum @@ -352,7 +350,6 @@ rb_stat_nlink(VALUE self) return UINT2NUM(get_stat(self)->st_nlink); } - /* * call-seq: * stat.uid => fixnum @@ -385,7 +382,6 @@ rb_stat_gid(VALUE self) return GIDT2NUM(get_stat(self)->st_gid); } - /* * call-seq: * stat.rdev => fixnum or nil @@ -839,7 +835,6 @@ rb_file_s_lstat(VALUE klass, VALUE fname) #endif } - /* * call-seq: * file.lstat => stat @@ -965,7 +960,6 @@ eaccess(const char *path, int mode) * */ - /* * File.directory?(file_name) => true or false * File.directory?(file_name) => true or false @@ -1014,7 +1008,6 @@ rb_file_directory_p(VALUE obj, VALUE fname) return Qfalse; } - /* * call-seq: * File.pipe?(file_name) => true or false @@ -1158,7 +1151,6 @@ rb_file_chardev_p(VALUE obj, VALUE fname) return Qfalse; } - /* * call-seq: * File.exist?(file_name) => true or false @@ -2019,7 +2011,6 @@ lchown_internal(const char *path, void *arg) rb_sys_fail(path); } - /* * call-seq: * file.lchown(owner_int, group_int, file_name,..) => integer @@ -2156,7 +2147,6 @@ rb_file_s_utime(int argc, VALUE *argv) return LONG2FIX(n); } - NORETURN(static void sys_fail2(VALUE,VALUE)); static void sys_fail2(VALUE s1, VALUE s2) @@ -3725,7 +3715,6 @@ rb_f_test(int argc, VALUE *argv) } - /* * Document-class: File::Stat * @@ -4028,8 +4017,6 @@ rb_stat_r(VALUE obj) return Qtrue; } - - /* * call-seq: * stat.readable_real? -> true or false @@ -4226,7 +4213,6 @@ rb_stat_x(VALUE obj) * the process. */ - static VALUE rb_stat_X(VALUE obj) { @@ -4287,7 +4273,6 @@ rb_stat_z(VALUE obj) return Qfalse; } - /* * call-seq: * state.size => integer @@ -4482,7 +4467,19 @@ rb_path_check(const char *path) static int file_load_ok(const char *path) { - return eaccess(path, R_OK) == 0; + int ret = 1; + int fd = open(path, O_RDONLY); + if (fd == -1) return 0; +#if !defined DOSISH + { + struct stat st; + if (fstat(fd, &st) || !S_ISREG(st.st_mode)) { + ret = 0; + } + } +#endif + (void)close(fd); + return ret; } static int -- cgit v1.2.3