From 22c005569b8cd00ea6895dcc7b621b80d9f15068 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 19 Jan 2004 09:19:31 +0000 Subject: * variable.c (rb_set_class_path): do not set path if * lib/cgi.rb (CGI::QueryExtension): give extended string, not a delegater object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 10 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index 7fc3f547ad..1acb858fd1 100644 --- a/file.c +++ b/file.c @@ -1046,12 +1046,7 @@ test_wr(obj, fname) if (rb_stat(fname, &st) < 0) return Qnil; if ((st.st_mode & (S_IROTH)) == S_IROTH) { -#ifdef __BORLANDC__ - return UINT2NUM((unsigned short)(st.st_mode & - (S_IRUGO|S_IWUGO|S_IXUGO))); -#else return UINT2NUM(st.st_mode & (S_IRUGO|S_IWUGO|S_IXUGO)); -#endif } #endif return Qnil; @@ -1114,12 +1109,7 @@ test_ww(obj, fname) if (rb_stat(fname, &st) < 0) return Qfalse; if ((st.st_mode & (S_IWOTH)) == S_IWOTH) { -#ifdef __BORLANDC__ - return UINT2NUM((unsigned short)(st.st_mode & - (S_IRUGO|S_IWUGO|S_IXUGO))); -#else return UINT2NUM(st.st_mode & (S_IRUGO|S_IWUGO|S_IXUGO)); -#endif } #endif return Qnil; @@ -3576,6 +3566,33 @@ rb_stat_R(obj) return Qtrue; } +/* + * call-seq: + * stat.world_readable? => fixnum or nil + * + * If stat is readable by others, returns an integer + * representing the file permission bits of stat. Returns + * nil otherwise. The meaning of the bits is platform + * dependent; on Unix systems, see stat(2). + * + * m = File.stat("/etc/passwd").world_readable? # => 420 + * sprintf("%o", m) # => "644" + */ + +static VALUE +rb_stat_wr(obj) + VALUE obj; +{ +#ifdef S_IROTH + if ((get_stat(obj)->st_mode & (S_IROTH)) == S_IROTH) { + return UINT2NUM(get_stat(obj)->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO)); + } + else { + return Qnil; + } +#endif +} + /* * call-seq: * stat.writable? -> true or false @@ -3638,6 +3655,33 @@ rb_stat_W(obj) return Qtrue; } +/* + * call-seq: + * stat.world_writable? => fixnum or nil + * + * If stat is writable by others, returns an integer + * representing the file permission bits of stat. Returns + * nil otherwise. The meaning of the bits is platform + * dependent; on Unix systems, see stat(2). + * + * m = File.stat("/tmp").world_writable? # => 511 + * sprintf("%o", m) # => "777" + */ + +static VALUE +rb_stat_ww(obj) + VALUE obj; +{ +#ifdef S_IROTH + if ((get_stat(obj)->st_mode & (S_IWOTH)) == S_IWOTH) { + return UINT2NUM(get_stat(obj)->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO)); + } + else { + return Qnil; + } +#endif +} + /* * call-seq: * stat.executable? => true or false @@ -4248,8 +4292,10 @@ Init_File() rb_define_method(rb_cStat, "directory?", rb_stat_d, 0); rb_define_method(rb_cStat, "readable?", rb_stat_r, 0); rb_define_method(rb_cStat, "readable_real?", rb_stat_R, 0); + rb_define_method(rb_cStat, "world_readable?", rb_stat_wr, 0); rb_define_method(rb_cStat, "writable?", rb_stat_w, 0); rb_define_method(rb_cStat, "writable_real?", rb_stat_W, 0); + rb_define_method(rb_cStat, "world_writable?", rb_stat_ww, 0); rb_define_method(rb_cStat, "executable?", rb_stat_x, 0); rb_define_method(rb_cStat, "executable_real?", rb_stat_X, 0); rb_define_method(rb_cStat, "file?", rb_stat_f, 0); -- cgit v1.2.3