mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* file.c (test_wr, test_ww): New functions implementing new
methods (File::world_readable?, File::world_writable?). * file.c (S_IRUGO, S_IGUGO): New macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a1d3a8e861
commit
a739d26d0a
3 changed files with 91 additions and 1 deletions
|
@ -1,3 +1,10 @@
|
|||
Mon Jan 12 18:00:11 2004 Ian Macdonald <ian@caliban.org>
|
||||
|
||||
* file.c (test_wr, test_ww): New functions implementing new
|
||||
methods (File::world_readable?, File::world_writable?).
|
||||
|
||||
* file.c (S_IRUGO, S_IGUGO): New macros.
|
||||
|
||||
Mon Jan 12 12:07:22 2004 Dave Thomas <dave@pragprog.com>
|
||||
|
||||
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::do_methods):
|
||||
|
|
83
file.c
83
file.c
|
@ -1015,6 +1015,50 @@ test_R(obj, fname)
|
|||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* File.world_readable?(file_name) => fixnum or nil
|
||||
*
|
||||
* If <i>file_name</i> is readable by others, returns an integer
|
||||
* representing the file permission bits of <i>file_name</i>. Returns
|
||||
* <code>nil</code> otherwise. The meaning of the bits is platform
|
||||
* dependent; on Unix systems, see <code>stat(2)</code>.
|
||||
*
|
||||
* File.world_readable?("/etc/passwd") # => 420
|
||||
* m = File.world_readable?("/etc/passwd")
|
||||
* sprintf("%o", m) # => "644"
|
||||
*/
|
||||
|
||||
#ifndef S_IRUGO
|
||||
# define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
|
||||
#endif
|
||||
|
||||
#ifndef S_IWUGO
|
||||
# define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
|
||||
#endif
|
||||
|
||||
static VALUE
|
||||
test_wr(obj, fname)
|
||||
VALUE obj, fname;
|
||||
{
|
||||
#ifdef S_IROTH
|
||||
struct stat st;
|
||||
|
||||
if (rb_stat(fname, &st) < 0) return Qfalse;
|
||||
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
|
||||
}
|
||||
else {
|
||||
return Qnil;
|
||||
}
|
||||
#endif
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
|
@ -1050,6 +1094,43 @@ test_W(obj, fname)
|
|||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* File.world_writable?(file_name) => fixnum or nil
|
||||
*
|
||||
* If <i>file_name</i> is writable by others, returns an integer
|
||||
* representing the file permission bits of <i>file_name</i>. Returns
|
||||
* <code>nil</code> otherwise. The meaning of the bits is platform
|
||||
* dependent; on Unix systems, see <code>stat(2)</code>.
|
||||
*
|
||||
* File.world_writable?("/tmp") #=> 511
|
||||
* m = File.world_writable?("/tmp")
|
||||
* sprintf("%o", m) #=> "777"
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
test_ww(obj, fname)
|
||||
VALUE obj, fname;
|
||||
{
|
||||
#ifdef S_IWOTH
|
||||
struct stat st;
|
||||
|
||||
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
|
||||
}
|
||||
else {
|
||||
return Qnil;
|
||||
}
|
||||
#endif
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* File.executable?(file_name) => true or false
|
||||
|
@ -4052,8 +4133,10 @@ Init_File()
|
|||
define_filetest_function("exists?", test_e, 1); /* temporary */
|
||||
define_filetest_function("readable?", test_r, 1);
|
||||
define_filetest_function("readable_real?", test_R, 1);
|
||||
define_filetest_function("world_readable?", test_wr, 1);
|
||||
define_filetest_function("writable?", test_w, 1);
|
||||
define_filetest_function("writable_real?", test_W, 1);
|
||||
define_filetest_function("world_writable?", test_ww, 1);
|
||||
define_filetest_function("executable?", test_x, 1);
|
||||
define_filetest_function("executable_real?", test_X, 1);
|
||||
define_filetest_function("file?", test_f, 1);
|
||||
|
|
|
@ -923,7 +923,7 @@ class CGI
|
|||
|
||||
%w[ CONTENT_LENGTH SERVER_PORT ].each do |env|
|
||||
define_method(env.sub(/^HTTP_/n, '').downcase) do
|
||||
val = env_table[env] && Integer(val)
|
||||
(val = env_table[env]) && Integer(val)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue